Skip to content

Commit

Permalink
add cmake compile flag for disabling cut metric
Browse files Browse the repository at this point in the history
  • Loading branch information
kittobi1992 committed Jul 20, 2023
1 parent a6f7bfa commit 222113d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/branch_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
rm -rf build
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_CI_BUILD=ON -DKAHYPAR_ENABLE_STEINER_TREE_METRIC=OFF -DKAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES=OFF -DKAHYPAR_ENABLE_QUALITY_PRESET_FEATURES=OFF -DKAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES=OFF
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_CI_BUILD=ON -DKAHYPAR_ENABLE_CUT_METRIC=OFF -DKAHYPAR_ENABLE_SOED_METRIC=OFF -DKAHYPAR_ENABLE_STEINER_TREE_METRIC=OFF -DKAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES=OFF -DKAHYPAR_ENABLE_QUALITY_PRESET_FEATURES=OFF -DKAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES=OFF
make -j2 MtKaHyPar
mt_kahypar_test_suite:
Expand All @@ -63,7 +63,7 @@ jobs:
rm -rf build
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_USE_GCOV=ON -DKAHYPAR_CI_BUILD=ON -DKAHYPAR_ENABLE_STEINER_TREE_METRIC=OFF -DKAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES=OFF -DKAHYPAR_ENABLE_QUALITY_PRESET_FEATURES=OFF -DKAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES=OFF
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_USE_GCOV=ON -DKAHYPAR_CI_BUILD=ON -DKAHYPAR_ENABLE_CUT_METRIC=OFF -DKAHYPAR_ENABLE_SOED_METRIC=OFF -DKAHYPAR_ENABLE_STEINER_TREE_METRIC=OFF -DKAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES=OFF -DKAHYPAR_ENABLE_QUALITY_PRESET_FEATURES=OFF -DKAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES=OFF
make -j2 mt_kahypar_tests;
- name: Run Mt-KaHyPar Tests
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ option(KAHYPAR_ENABLE_QUALITY_PRESET_FEATURES
option(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES
"Enables large k partitioning features. Can be turned off for faster compilation." ON)

option(KAHYPAR_ENABLE_CUT_METRIC
"Enables the cut metric. Can be turned off for faster compilation." ON)

option(KAHYPAR_ENABLE_SOED_METRIC
"Enables the sum-of-external-degree metric. Can be turned off for faster compilation." ON)

Expand Down Expand Up @@ -128,6 +131,10 @@ if(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES)
add_compile_definitions(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES)
endif(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES)

if(KAHYPAR_ENABLE_CUT_METRIC)
add_compile_definitions(KAHYPAR_ENABLE_CUT_METRIC)
endif(KAHYPAR_ENABLE_CUT_METRIC)

if(KAHYPAR_ENABLE_SOED_METRIC)
add_compile_definitions(KAHYPAR_ENABLE_SOED_METRIC)
endif(KAHYPAR_ENABLE_SOED_METRIC)
Expand Down
6 changes: 6 additions & 0 deletions mt-kahypar/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@
#define ENABLE_QUALITY_PRESET_FOR_GRAPHS(X)
#endif

#ifdef KAHYPAR_ENABLE_CUT_METRIC
#define ENABLE_CUT(X) X
#else
#define ENABLE_CUT(X)
#endif

#ifdef KAHYPAR_ENABLE_SOED_METRIC
#define ENABLE_SOED(X) X
#else
Expand Down
7 changes: 7 additions & 0 deletions mt-kahypar/partition/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ namespace mt_kahypar {
}

void Context::setupGainPolicy() {
#ifndef KAHYPAR_ENABLE_CUT_METRIC
if ( partition.objective == Objective::cut ) {
ERR("Cut metric is deactivated. Add -DKAHYPAR_ENABLE_CUT_METRIC=ON"
<< "to the cmake command and rebuild Mt-KaHyPar.");
}
#endif

#ifndef KAHYPAR_ENABLE_SOED_METRIC
if ( partition.objective == Objective::soed ) {
ERR("SOED metric is deactivated. Add -DKAHYPAR_ENABLE_SOED_METRIC=ON"
Expand Down
2 changes: 2 additions & 0 deletions mt-kahypar/partition/deep_multilevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,12 @@ void bipartition_each_block(typename TypeTraits::PartitionedHypergraph& partitio
const HyperedgeWeight current_objective,
const bool progress_bar_enabled) {
switch(gain_cache.type) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut:
bipartition_each_block<TypeTraits>(partitioned_hg, context,
GainCachePtr::cast<CutGainCache>(gain_cache), info, rb_tree,
already_cut, current_k, current_objective, progress_bar_enabled); break;
#endif
case GainPolicy::km1:
bipartition_each_block<TypeTraits>(partitioned_hg, context,
GainCachePtr::cast<Km1GainCache>(gain_cache), info, rb_tree,
Expand Down
5 changes: 4 additions & 1 deletion mt-kahypar/partition/refinement/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ set(SteinerTreeGraphSources
foreach(modtarget IN LISTS PARTITIONING_SUITE_TARGETS)
target_sources(${modtarget} PRIVATE ${RefinementSources})
target_sources(${modtarget} PRIVATE ${Km1Sources})
target_sources(${modtarget} PRIVATE ${CutSources})

if ( KAHYPAR_ENABLE_CUT_METRIC )
target_sources(${modtarget} PRIVATE ${CutSources})
endif()

if ( KAHYPAR_ENABLE_SOED_METRIC )
target_sources(${modtarget} PRIVATE ${SoedSources})
Expand Down
18 changes: 18 additions & 0 deletions mt-kahypar/partition/refinement/gains/gain_cache_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
#include "mt-kahypar/partition/context_enum_classes.h"
#include "mt-kahypar/datastructures/hypergraph_common.h"
#include "mt-kahypar/partition/refinement/gains/km1/km1_gain_cache.h"
#ifdef KAHYPAR_ENABLE_CUT_METRIC
#include "mt-kahypar/partition/refinement/gains/cut/cut_gain_cache.h"
#endif
#ifdef KAHYPAR_ENABLE_SOED_METRIC
#include "mt-kahypar/partition/refinement/gains/soed/soed_gain_cache.h"
#endif
#ifdef KAHYPAR_ENABLE_STEINER_TREE_METRIC
#include "mt-kahypar/partition/refinement/gains/steiner_tree/steiner_tree_gain_cache.h"
#endif
Expand All @@ -58,7 +62,9 @@ class GainCachePtr {
public:
static gain_cache_t constructGainCache(const Context& context) {
switch(context.partition.gain_policy) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut: return constructGainCache<CutGainCache>(context);
#endif
case GainPolicy::km1: return constructGainCache<Km1GainCache>(context);
#ifdef KAHYPAR_ENABLE_SOED_METRIC
case GainPolicy::soed: return constructGainCache<SoedGainCache>(context);
Expand All @@ -80,8 +86,10 @@ class GainCachePtr {
static void deleteGainCache(gain_cache_t gain_cache) {
if ( gain_cache.gain_cache ) {
switch(gain_cache.type) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut:
delete reinterpret_cast<CutGainCache*>(gain_cache.gain_cache); break;
#endif
case GainPolicy::km1:
delete reinterpret_cast<Km1GainCache*>(gain_cache.gain_cache); break;
#ifdef KAHYPAR_ENABLE_SOED_METRIC
Expand Down Expand Up @@ -110,7 +118,9 @@ class GainCachePtr {
static void initializeGainCache(const PartitionedHypergraph& partitioned_hg,
gain_cache_t gain_cache) {
switch(gain_cache.type) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut: cast<CutGainCache>(gain_cache).initializeGainCache(partitioned_hg); break;
#endif
case GainPolicy::km1: cast<Km1GainCache>(gain_cache).initializeGainCache(partitioned_hg); break;
#ifdef KAHYPAR_ENABLE_SOED_METRIC
case GainPolicy::soed: cast<SoedGainCache>(gain_cache).initializeGainCache(partitioned_hg); break;
Expand All @@ -130,7 +140,9 @@ class GainCachePtr {

static void resetGainCache(gain_cache_t gain_cache) {
switch(gain_cache.type) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut: cast<CutGainCache>(gain_cache).reset(); break;
#endif
case GainPolicy::km1: cast<Km1GainCache>(gain_cache).reset(); break;
#ifdef KAHYPAR_ENABLE_SOED_METRIC
case GainPolicy::soed: cast<SoedGainCache>(gain_cache).reset(); break;
Expand All @@ -154,7 +166,9 @@ class GainCachePtr {
const Batch& batch,
gain_cache_t gain_cache) {
switch(gain_cache.type) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut: partitioned_hg.uncontract(batch, cast<CutGainCache>(gain_cache)); break;
#endif
case GainPolicy::km1: partitioned_hg.uncontract(batch, cast<Km1GainCache>(gain_cache)); break;
#ifdef KAHYPAR_ENABLE_SOED_METRIC
case GainPolicy::soed: partitioned_hg.uncontract(batch, cast<SoedGainCache>(gain_cache)); break;
Expand All @@ -176,9 +190,11 @@ class GainCachePtr {
const vec<ParallelHyperedge>& hes_to_restore,
gain_cache_t gain_cache) {
switch ( gain_cache.type ) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut:
partitioned_hg.restoreSinglePinAndParallelNets(hes_to_restore,
cast<CutGainCache>(gain_cache)); break;
#endif
case GainPolicy::km1:
partitioned_hg.restoreSinglePinAndParallelNets(hes_to_restore,
cast<Km1GainCache>(gain_cache)); break;
Expand Down Expand Up @@ -211,9 +227,11 @@ class GainCachePtr {
static bool checkTrackedPartitionInformation(PartitionedHypergraph& partitioned_hg,
gain_cache_t gain_cache) {
switch ( gain_cache.type ) {
#ifdef KAHYPAR_ENABLE_CUT_METRIC
case GainPolicy::cut:
return partitioned_hg.checkTrackedPartitionInformation(
cast<CutGainCache>(gain_cache));
#endif
case GainPolicy::km1:
return partitioned_hg.checkTrackedPartitionInformation(
cast<Km1GainCache>(gain_cache));
Expand Down
10 changes: 7 additions & 3 deletions mt-kahypar/partition/refinement/gains/gain_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
#include "mt-kahypar/partition/refinement/gains/km1/km1_gain_computation.h"
#include "mt-kahypar/partition/refinement/gains/km1/km1_attributed_gains.h"
#include "mt-kahypar/partition/refinement/gains/km1/km1_flow_network_construction.h"
#ifdef KAHYPAR_ENABLE_CUT_METRIC
#include "mt-kahypar/partition/refinement/gains/cut/cut_gain_cache.h"
#include "mt-kahypar/partition/refinement/gains/cut/cut_rollback.h"
#include "mt-kahypar/partition/refinement/gains/cut/cut_gain_computation.h"
#include "mt-kahypar/partition/refinement/gains/cut/cut_attributed_gains.h"
#include "mt-kahypar/partition/refinement/gains/cut/cut_flow_network_construction.h"
#endif
#ifdef KAHYPAR_ENABLE_SOED_METRIC
#include "mt-kahypar/partition/refinement/gains/soed/soed_attributed_gains.h"
#include "mt-kahypar/partition/refinement/gains/soed/soed_gain_computation.h"
Expand Down Expand Up @@ -79,6 +81,7 @@ struct Km1GainTypes : public kahypar::meta::PolicyBase {
using FlowNetworkConstruction = Km1FlowNetworkConstruction;
};

#ifdef KAHYPAR_ENABLE_CUT_METRIC
struct CutGainTypes : public kahypar::meta::PolicyBase {
using GainComputation = CutGainComputation;
using AttributedGains = CutAttributedGains;
Expand All @@ -87,6 +90,7 @@ struct CutGainTypes : public kahypar::meta::PolicyBase {
using Rollback = CutRollback;
using FlowNetworkConstruction = CutFlowNetworkConstruction;
};
#endif

#ifdef KAHYPAR_ENABLE_SOED_METRIC
struct SoedGainTypes : public kahypar::meta::PolicyBase {
Expand Down Expand Up @@ -133,16 +137,16 @@ struct SteinerTreeForGraphsTypes : public kahypar::meta::PolicyBase {
#endif


using GainTypes = kahypar::meta::Typelist<Km1GainTypes,
CutGainTypes
using GainTypes = kahypar::meta::Typelist<Km1GainTypes
ENABLE_CUT(COMMA CutGainTypes)
ENABLE_SOED(COMMA SoedGainTypes)
ENABLE_STEINER_TREE(COMMA SteinerTreeGainTypes)
ENABLE_GRAPHS(COMMA CutGainForGraphsTypes)
ENABLE_GRAPHS(ENABLE_STEINER_TREE(COMMA SteinerTreeForGraphsTypes))>;

#define INSTANTIATE_CLASS_WITH_TYPE_TRAITS_AND_GAIN_TYPES(C) \
INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, Km1GainTypes) \
INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, CutGainTypes) \
ENABLE_CUT(INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, CutGainTypes)) \
ENABLE_SOED(INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, SoedGainTypes)) \
ENABLE_STEINER_TREE(INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, SteinerTreeGainTypes)) \
ENABLE_GRAPHS(INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, CutGainForGraphsTypes)) \
Expand Down
2 changes: 2 additions & 0 deletions mt-kahypar/partition/registries/register_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ REGISTER_POLICY(AcceptancePolicy, AcceptancePolicy::best,
// Gain Type Policies
// //////////////////////////////////////////////////////////////////////////////
REGISTER_POLICY(GainPolicy, GainPolicy::km1, Km1GainTypes);
#ifdef KAHYPAR_ENABLE_CUT_METRIC
REGISTER_POLICY(GainPolicy, GainPolicy::cut, CutGainTypes);
#endif
#ifdef KAHYPAR_ENABLE_SOED_METRIC
REGISTER_POLICY(GainPolicy, GainPolicy::soed, SoedGainTypes);
#endif
Expand Down
4 changes: 2 additions & 2 deletions tests/partition/refinement/bipartitioning_gain_policy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class ABipartitioningPolicy : public Test {
Context context;
};

typedef ::testing::Types<ObjectiveF<Objective::cut>,
ObjectiveF<Objective::km1>
typedef ::testing::Types<ObjectiveF<Objective::km1>
ENABLE_CUT(COMMA ObjectiveF<Objective::cut>)
ENABLE_SOED(COMMA ObjectiveF<Objective::soed>)> TestConfigs;

TYPED_TEST_CASE(ABipartitioningPolicy, TestConfigs);
Expand Down
12 changes: 6 additions & 6 deletions tests/partition/refinement/gain_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,20 @@ class AGainCache : public Test {
ds::ThreadSafeFastResetFlagArray<> was_moved;
};

typedef ::testing::Types<TestConfig<StaticHypergraphTypeTraits, Km1GainTypes>,
TestConfig<StaticHypergraphTypeTraits, CutGainTypes>
typedef ::testing::Types<TestConfig<StaticHypergraphTypeTraits, Km1GainTypes>
ENABLE_CUT(COMMA TestConfig<StaticHypergraphTypeTraits COMMA CutGainTypes>)
ENABLE_SOED(COMMA TestConfig<StaticHypergraphTypeTraits COMMA SoedGainTypes>)
ENABLE_STEINER_TREE(COMMA TestConfig<StaticHypergraphTypeTraits COMMA SteinerTreeGainTypes>)
ENABLE_GRAPHS(COMMA TestConfig<StaticGraphTypeTraits COMMA CutGainForGraphsTypes>)
ENABLE_GRAPHS(ENABLE_CUT(COMMA TestConfig<StaticGraphTypeTraits COMMA CutGainForGraphsTypes>))
ENABLE_GRAPHS(ENABLE_STEINER_TREE(COMMA TestConfig<StaticGraphTypeTraits COMMA SteinerTreeForGraphsTypes>))
ENABLE_QUALITY_PRESET(COMMA TestConfig<DynamicHypergraphTypeTraits COMMA Km1GainTypes>)
ENABLE_QUALITY_PRESET(COMMA TestConfig<DynamicHypergraphTypeTraits COMMA CutGainTypes>)
ENABLE_QUALITY_PRESET(ENABLE_CUT(COMMA TestConfig<DynamicHypergraphTypeTraits COMMA CutGainTypes>))
ENABLE_QUALITY_PRESET(ENABLE_SOED(COMMA TestConfig<DynamicHypergraphTypeTraits COMMA SoedGainTypes>))
ENABLE_QUALITY_PRESET(ENABLE_STEINER_TREE(COMMA TestConfig<DynamicHypergraphTypeTraits COMMA SteinerTreeGainTypes>))
ENABLE_QUALITY_PRESET_FOR_GRAPHS(COMMA TestConfig<DynamicGraphTypeTraits COMMA CutGainForGraphsTypes>)
ENABLE_QUALITY_PRESET_FOR_GRAPHS(ENABLE_CUT(COMMA TestConfig<DynamicGraphTypeTraits COMMA CutGainForGraphsTypes>))
ENABLE_QUALITY_PRESET_FOR_GRAPHS(ENABLE_STEINER_TREE(COMMA TestConfig<DynamicGraphTypeTraits COMMA SteinerTreeForGraphsTypes>))
ENABLE_LARGE_K(COMMA TestConfig<LargeKHypergraphTypeTraits COMMA Km1GainTypes>)
ENABLE_LARGE_K(COMMA TestConfig<LargeKHypergraphTypeTraits COMMA CutGainTypes>)
ENABLE_LARGE_K(ENABLE_CUT(COMMA TestConfig<LargeKHypergraphTypeTraits COMMA CutGainTypes>))
ENABLE_LARGE_K(ENABLE_SOED(COMMA TestConfig<LargeKHypergraphTypeTraits COMMA SoedGainTypes>))
ENABLE_LARGE_K(ENABLE_STEINER_TREE(COMMA TestConfig<LargeKHypergraphTypeTraits COMMA SteinerTreeGainTypes>))> TestConfigs;

Expand Down

0 comments on commit 222113d

Please sign in to comment.