Skip to content

Commit 6c889a1

Browse files
committed
added const_graph_t template argument to OrbitGraphProcessor
1 parent c9321f1 commit 6c889a1

File tree

6 files changed

+43
-30
lines changed

6 files changed

+43
-30
lines changed

include/osp/dag_divider/isomorphism_divider/IsomorphicSubgraphScheduler.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ limitations under the License.
2626

2727
namespace osp {
2828

29-
3029
template<typename Graph_t, typename Constr_Graph_t>
3130
class IsomorphicSubgraphScheduler {
31+
static_assert(is_computational_dag_v<Graph_t>, "Graph must be a computational DAG");
32+
static_assert(is_computational_dag_v<Constr_Graph_t>, "Constr_Graph_t must be a computational DAG");
33+
static_assert(is_constructable_cdag_v<Constr_Graph_t>,
34+
"Constr_Graph_t must satisfy the constructable_cdag_vertex concept");
35+
static_assert(std::is_same_v<vertex_idx_t<Graph_t>, vertex_idx_t<Constr_Graph_t>>,
36+
"Graph_t and Constr_Graph_t must have the same vertex_idx types");
3237

3338
private:
3439

@@ -53,7 +58,7 @@ class IsomorphicSubgraphScheduler {
5358
}
5459

5560
std::vector<vertex_idx_t<Graph_t>> compute_partition(const BspInstance<Graph_t>& instance) {
56-
OrbitGraphProcessor<Graph_t> processor(symmetry_);
61+
OrbitGraphProcessor<Graph_t, Constr_Graph_t> processor(symmetry_);
5762
processor.discover_isomorphic_groups(instance.getComputationalDag());
5863
const auto& orbit_processor_groups = processor.get_final_groups();
5964

@@ -68,8 +73,6 @@ class IsomorphicSubgraphScheduler {
6873
for (const auto& sg_vertices : group.subgraphs) {
6974
subgraph<Graph_t> new_sg;
7075
new_sg.vertices = sg_vertices;
71-
// The following properties are not directly provided by OrbitGraphProcessor
72-
// but are needed by downstream logic. We can compute them.
7376
new_sg.work_weight = 0;
7477
new_sg.memory_weight = 0;
7578
for (const auto& v : sg_vertices) {

include/osp/dag_divider/isomorphism_divider/OrbitGraphProcessor.hpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ namespace osp {
3838
* It then partitions the DAG by grouping all nodes with the same hash into an "orbit".
3939
* A coarse graph is constructed where each node represents one such orbit.
4040
*/
41-
template<typename Graph_t, typename node_hash_func_t = uniform_node_hash_func<vertex_idx_t<Graph_t>>>
41+
template<typename Graph_t, typename Constr_Graph_t>
4242
class OrbitGraphProcessor {
4343
public:
44+
static_assert(is_computational_dag_v<Graph_t>, "Graph must be a computational DAG");
45+
static_assert(is_computational_dag_v<Constr_Graph_t>, "Constr_Graph_t must be a computational DAG");
46+
static_assert(is_constructable_cdag_v<Constr_Graph_t>,
47+
"Constr_Graph_t must satisfy the constructable_cdag_vertex concept");
48+
static_assert(std::is_same_v<vertex_idx_t<Graph_t>, vertex_idx_t<Constr_Graph_t>>,
49+
"Graph_t and Constr_Graph_t must have the same vertex_idx types");
50+
4451
using VertexType = vertex_idx_t<Graph_t>;
4552

4653
// Represents a group of isomorphic subgraphs, corresponding to a single node in a coarse graph.
@@ -57,11 +64,11 @@ class OrbitGraphProcessor {
5764
// using MerkleHashComputer_t = MerkleHashComputer<Graph_t, node_hash_func_t, true>;
5865

5966
// Results from the first (orbit) coarsening step
60-
Graph_t coarse_graph_;
67+
Constr_Graph_t coarse_graph_;
6168
std::vector<VertexType> contraction_map_;
6269

6370
// Results from the second (custom) coarsening step
64-
Graph_t final_coarse_graph_;
71+
Constr_Graph_t final_coarse_graph_;
6572
std::vector<VertexType> final_contraction_map_;
6673
std::vector<Group> final_groups_;
6774

@@ -86,9 +93,9 @@ class OrbitGraphProcessor {
8693
* @param dag The input computational DAG.
8794
*/
8895
void discover_isomorphic_groups(const Graph_t &dag) {
89-
coarse_graph_ = Graph_t();
96+
coarse_graph_ = Constr_Graph_t();
9097
contraction_map_.clear();
91-
final_coarse_graph_ = Graph_t();
98+
final_coarse_graph_ = Constr_Graph_t();
9299
final_contraction_map_.clear();
93100
final_groups_.clear();
94101

@@ -111,7 +118,7 @@ class OrbitGraphProcessor {
111118

112119
coarser_util::construct_coarse_dag(dag, coarse_graph_, contraction_map_);
113120

114-
Graph_t transitive_reduction;
121+
Constr_Graph_t transitive_reduction;
115122
transitive_reduction_sparse(coarse_graph_, transitive_reduction);
116123
coarse_graph_ = std::move(transitive_reduction);
117124

@@ -123,15 +130,15 @@ class OrbitGraphProcessor {
123130
/**
124131
* @brief Greedily merges nodes in the orbit graph based on structural and symmetry constraints.
125132
*/
126-
void perform_coarsening(const Graph_t& original_dag, const Graph_t& initial_coarse_graph) {
127-
final_coarse_graph_ = Graph_t();
133+
void perform_coarsening(const Graph_t& original_dag, const Constr_Graph_t& initial_coarse_graph) {
134+
final_coarse_graph_ = Constr_Graph_t();
128135
final_contraction_map_.clear();
129136

130137
if (initial_coarse_graph.num_vertices() == 0) {
131138
return;
132139
}
133140

134-
Graph_t current_coarse_graph = initial_coarse_graph;
141+
Constr_Graph_t current_coarse_graph = initial_coarse_graph;
135142
std::vector<Group> current_groups(initial_coarse_graph.num_vertices());
136143
std::vector<VertexType> current_contraction_map = contraction_map_;
137144

@@ -166,7 +173,7 @@ class OrbitGraphProcessor {
166173
}
167174

168175
// 2. Acyclicity & Critical Path
169-
Graph_t temp_coarse_graph;
176+
Constr_Graph_t temp_coarse_graph;
170177
std::vector<VertexType> temp_contraction_map(current_coarse_graph.num_vertices());
171178
VertexType new_idx = 0;
172179
for (VertexType i = 0; i < temp_contraction_map.size(); ++i) {
@@ -276,7 +283,7 @@ class OrbitGraphProcessor {
276283
std::sort(all_nodes.begin(), all_nodes.end());
277284

278285
// 2. Create an induced subgraph and find its weakly connected components.
279-
Graph_t induced_subgraph;
286+
Constr_Graph_t induced_subgraph;
280287
create_induced_subgraph(original_dag, induced_subgraph, all_nodes);
281288

282289
std::vector<VertexType> components; // local -> component_id

include/osp/graph_implementations/eigen_sparse_iterator.hpp renamed to include/osp/graph_implementations/eigen_matrix_adapter/eigen_sparse_iterator.hpp

File renamed without changes.

include/osp/graph_implementations/eigen_matrix_adapter/sparse_matrix.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
#include "osp/concepts/directed_graph_edge_desc_concept.hpp"
2626
#include "osp/concepts/computational_dag_concept.hpp"
2727
#include "osp/graph_implementations/vertex_iterator.hpp"
28-
#include "osp/graph_implementations/eigen_sparse_iterator.hpp"
28+
#include "eigen_sparse_iterator.hpp"
2929

3030
namespace osp {
3131

tests/merkle_hash_divider.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ limitations under the License.
2323
#include "osp/dag_divider/wavefront_divider/RecursiveWavefrontDivider.hpp"
2424
#include "osp/graph_algorithms/directed_graph_util.hpp"
2525
#include "osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp"
26+
#include "osp/graph_implementations/adj_list_impl/dag_vector_adapter.hpp"
2627
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
2728
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
2829
#include "osp/auxiliary/io/DotFileWriter.hpp"
@@ -42,9 +43,11 @@ using namespace osp;
4243
BOOST_AUTO_TEST_CASE(BspScheduleRecomp_test)
4344
{
4445
using graph_t = computational_dag_vector_impl_def_t;
45-
46-
BspInstance<graph_t> instance;
47-
file_reader::readComputationalDagDotFormat("", instance.getComputationalDag());
46+
using graph_t2 = graph_t;
47+
//using graph_t2 = dag_vector_adapter<cdag_vertex_impl_unsigned,int>;
48+
49+
BspInstance<graph_t2> instance;
50+
//file_reader::readComputationalDagDotFormat("", instance.getComputationalDag());
4851

4952
for (const auto& v : instance.vertices()) {
5053

@@ -86,7 +89,7 @@ BOOST_AUTO_TEST_CASE(BspScheduleRecomp_test)
8689

8790
// auto schedule = pre_scheduler.run(input.instance, input.multiplicities, input.required_proc_types);
8891

89-
IsomorphicSubgraphScheduler<graph_t, graph_t> iso_scheduler(combo);
92+
IsomorphicSubgraphScheduler<graph_t2, graph_t> iso_scheduler(combo);
9093
iso_scheduler.set_symmetry(2);
9194
iso_scheduler.set_plot_dot_graphs(true);
9295

tests/orbit_graph_processor.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace osp;
3636
using graph_t = computational_dag_vector_impl_def_t;
3737

3838
template <typename Graph_t>
39-
void check_partitioning(const Graph_t& dag, const OrbitGraphProcessor<Graph_t>& processor) {
39+
void check_partitioning(const Graph_t& dag, const OrbitGraphProcessor<Graph_t, Graph_t>& processor) {
4040
const auto& final_coarse_graph = processor.get_final_coarse_graph();
4141
const auto& final_groups = processor.get_final_groups();
4242

@@ -66,7 +66,7 @@ void check_partitioning(const Graph_t& dag, const OrbitGraphProcessor<Graph_t>&
6666
// graph_t dag;
6767
// file_reader::readComputationalDagDotFormat("", dag);
6868

69-
// OrbitGraphProcessor<graph_t> processor(2); // Using a symmetry threshold of 2
69+
// OrbitGraphProcessor<graph_t, graph_t> processor(2); // Using a symmetry threshold of 2
7070
// processor.discover_isomorphic_groups(dag);
7171

7272
// const auto& coarse_graph = processor.get_coarse_graph();
@@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_SimpleMerge) {
118118

119119
// Initial orbits: {0, 2} and {1, 3}. Coarse graph: 0 -> 1
120120
// With threshold 2, these should be merged.
121-
OrbitGraphProcessor<graph_t> processor(2);
121+
OrbitGraphProcessor<graph_t, graph_t> processor(2);
122122
processor.discover_isomorphic_groups(dag);
123123

124124
const auto& final_coarse_graph = processor.get_final_coarse_graph();
@@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_ForkJoinNoMerge) {
155155
// Initial orbits: {0}, {1,2}, {3}. Coarse graph: 0 -> 1 -> 2
156156
// Merging 0 and 1 would result in a group of size 1 ({0,1,2}), which is not viable (threshold 2).
157157
// Merging 1 and 2 would also result in a group of size 1 ({1,2,3}), not viable.
158-
OrbitGraphProcessor<graph_t> processor(2);
158+
OrbitGraphProcessor<graph_t, graph_t> processor(2);
159159
processor.discover_isomorphic_groups(dag);
160160

161161
const auto& final_coarse_graph = processor.get_final_coarse_graph();
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_PartitionCheck_MediumGraph) {
189189
BOOST_REQUIRE_GT(dag.num_vertices(), 0);
190190

191191
// Use a higher threshold to encourage more merging on this larger graph
192-
OrbitGraphProcessor<graph_t> processor(4);
192+
OrbitGraphProcessor<graph_t, graph_t> processor(4);
193193
processor.discover_isomorphic_groups(dag);
194194

195195
// The main purpose of this test is to ensure the output is a valid partition.
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_MultiPipelineMerge) {
203203
const auto dag = construct_multi_pipeline_dag<graph_t>(5, 4);
204204
BOOST_REQUIRE_EQUAL(dag.num_vertices(), 20);
205205

206-
OrbitGraphProcessor<graph_t> processor(5); // Set threshold to match pipeline count
206+
OrbitGraphProcessor<graph_t, graph_t> processor(5); // Set threshold to match pipeline count
207207
processor.discover_isomorphic_groups(dag);
208208

209209
const auto& final_coarse_graph = processor.get_final_coarse_graph();
@@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_LadderNoMerge) {
230230
const auto dag = construct_ladder_dag<graph_t>(10);
231231
BOOST_REQUIRE_EQUAL(dag.num_vertices(), 22);
232232

233-
OrbitGraphProcessor<graph_t> processor(2);
233+
OrbitGraphProcessor<graph_t, graph_t> processor(2);
234234
processor.discover_isomorphic_groups(dag);
235235

236236
const auto& initial_coarse_graph = processor.get_coarse_graph();
@@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_AsymmetricNoMerge) {
249249
const auto dag = construct_asymmetric_dag<graph_t>(30);
250250
BOOST_REQUIRE_EQUAL(dag.num_vertices(), 30);
251251

252-
OrbitGraphProcessor<graph_t> processor(2);
252+
OrbitGraphProcessor<graph_t, graph_t> processor(2);
253253
processor.discover_isomorphic_groups(dag);
254254

255255
const auto& final_coarse_graph = processor.get_final_coarse_graph();
@@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_BinaryTreeNoMerge) {
270270
const auto dag = construct_binary_out_tree<graph_t>(4);
271271
BOOST_REQUIRE_EQUAL(dag.num_vertices(), (1 << 5) - 1);
272272

273-
OrbitGraphProcessor<graph_t> processor(2);
273+
OrbitGraphProcessor<graph_t, graph_t> processor(2);
274274
processor.discover_isomorphic_groups(dag);
275275

276276
const auto& final_coarse_graph = processor.get_final_coarse_graph();
@@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE(OrbitGraphProcessor_ButterflyMerge) {
289289
const auto dag = construct_butterfly_dag<graph_t>(3);
290290
BOOST_REQUIRE_EQUAL(dag.num_vertices(), (3 + 1) * 8);
291291

292-
OrbitGraphProcessor<graph_t> processor(16); // Threshold is larger than any group size
292+
OrbitGraphProcessor<graph_t, graph_t> processor(16); // Threshold is larger than any group size
293293
processor.discover_isomorphic_groups(dag);
294294

295295
const auto& final_coarse_graph = processor.get_final_coarse_graph();

0 commit comments

Comments
 (0)