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

Unity device mapping algorithm #1459

Draft
wants to merge 29 commits into
base: repo-refactor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
950da68
pass existing tests
Aug 5, 2024
d36d1ea
unity algorithm builds
Aug 7, 2024
c71b773
fmt
Aug 7, 2024
678e990
fix
Aug 21, 2024
ee2429c
Merge branch 'repo-refactor' into compiler_test
lockshaw Aug 22, 2024
49a4a0c
Merge remote-tracking branch 'flexflow/repo-refactor' into compiler_test
Aug 27, 2024
8e27f2a
refactor machine mapping
Aug 27, 2024
8191bcd
Merge branch 'compiler_test' of github.com:wmdi/FlexFlow into compile…
Aug 27, 2024
9b9f529
add unit tests
Aug 29, 2024
150ca5e
fmt
Aug 29, 2024
fc388ce
add more tests
Sep 2, 2024
e628c72
fmt
Sep 2, 2024
8eff2b9
fix
Sep 4, 2024
0d409e9
Merge remote-tracking branch 'flexflow/repo-refactor' into compiler_test
Sep 11, 2024
7c03f24
refactor get_optimal_machine_mapping a bit and improve the tests
Sep 12, 2024
89ed108
remove debug codes
Sep 12, 2024
a112225
Merge remote-tracking branch 'origin/repo-refactor' into wmdi-compile…
lockshaw Sep 18, 2024
3a35951
A lot of simplifying and modularizing of unity dp code
lockshaw Sep 26, 2024
00c2bae
Get tests building again
lockshaw Sep 27, 2024
3d9c9bb
Merge remote-tracking branch 'origin/repo-refactor' into wmdi-compile…
lockshaw Sep 27, 2024
7e73162
Get all the new testcases working
lockshaw Sep 28, 2024
bdcc10e
Move over to ProblemTree/ResultTree framework for machine mapping
lockshaw Sep 29, 2024
b0475b4
Settle on ProblemTree/BinaryTreePath-indexed-MachineMappingResult for…
lockshaw Sep 30, 2024
2bbec5c
More code cleanup and PR prep
lockshaw Oct 1, 2024
85fd5b4
Get tests building again
lockshaw Oct 2, 2024
597e13c
Pass some basic tests of get_optimal_machine_mapping
lockshaw Oct 3, 2024
0c2ab05
Migrate over to use type-erased binary tree
lockshaw Oct 3, 2024
e4073bc
Move back to templated FullBinaryTree
lockshaw Oct 3, 2024
5d22c6d
Get all existing tests passing again
lockshaw Oct 4, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/per-lib-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ jobs:
run: |
test_libs.sh substitutions

# - name: Test compiler
# run: |
# test_libs.sh compiler
- name: Test compiler
run: |
test_libs.sh compiler

- name: Test substitution-generator
run: |
Expand Down
16 changes: 16 additions & 0 deletions lib/compiler/include/compiler/graph_optimize_result.struct.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace = "FlexFlow"
name = "GraphOptimizeResult"
features = [ ]

includes = [
"compiler/machine_mapping/machine_mapping.dtg.h",
"pcg/parallel_computation_graph/parallel_computation_graph.h"
]

[[fields]]
name = "pcg"
type = "::FlexFlow::ParallelComputationGraph"

[[fields]]
name = "machine_mapping"
type = "::FlexFlow::MachineMapping"
31 changes: 31 additions & 0 deletions lib/compiler/include/compiler/graph_optimize_state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef _FLEXFLOW_COMPILER_MCMC_STATE_H
#define _FLEXFLOW_COMPILER_MCMC_STATE_H

#include "compiler/graph_optimize_result.dtg.h"

namespace FlexFlow {

struct GraphOptimizeState {
GraphOptimizeState(GraphOptimizeResult const &graph_optimize_result,
float runtime);

GraphOptimizeResult graph_optimize_result;
float runtime;

bool operator==(GraphOptimizeState const &other) const;
bool operator!=(GraphOptimizeState const &other) const;
bool operator<(GraphOptimizeState const &other) const;
};

} // namespace FlexFlow

namespace std {

template <>
struct hash<::FlexFlow::GraphOptimizeState> {
size_t operator()(::FlexFlow::GraphOptimizeState const &) const;
};

} // namespace std

#endif
37 changes: 0 additions & 37 deletions lib/compiler/include/compiler/graph_utils.h

This file was deleted.

69 changes: 0 additions & 69 deletions lib/compiler/include/compiler/machine_mapping.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef _FLEXFLOW_COMPILER_MACHINE_MAPPING_GET_OPTIMAL_MACHINE_MAPPING_H
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_GET_OPTIMAL_MACHINE_MAPPING_H

#include "machine_mapping.h"
#include "machine_mapping_cache.h"
#include "machine_mapping_context.dtg.h"
#include "pcg/machine_specification.h"
#include "pcg/machine_view.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"

namespace FlexFlow {

MachineMappingResult get_optimal_machine_mapping(
ParallelComputationGraph const &pcg,
std::function<std::unordered_set<MachineView>(
ParallelLayerAttrs const &, MachineSpecification const &)> const
&allowed_machine_views,
CostEstimator const &cost_estimator,
MachineSpecification const &resources,
MachineMappingCache &cached_subgraph_results);

MachineMappingResult
get_optimal_machine_mapping_internal(MachineMappingContext &context,
MachineSpecification const &resources);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
SerialParallelDecomposition const &decompn,
MachineSpecification const &resource,
std::unordered_map<OpenDataflowValue, MachineView> const
&fixed_machine_views);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
SerialSplit const &serial,
MachineSpecification const &resource,
std::unordered_map<OpenDataflowValue, MachineView> const
&fixed_machine_views);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
ParallelSplit const &parallel,
MachineSpecification const &resource,
std::unordered_map<OpenDataflowValue, MachineView> const
&fixed_machine_views);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
Node const &node,
MachineSpecification const &resource,
std::unordered_map<OpenDataflowValue, MachineView> const
&fixed_machine_views);

} // namespace FlexFlow

#endif
14 changes: 14 additions & 0 deletions lib/compiler/include/compiler/machine_mapping/machine_mapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _FLEXFLOW_COMPILER_MACHINE_MAPPING_H
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_H

#include "machine_mapping.dtg.h"

namespace FlexFlow {

MachineMapping combine(MachineMapping const &, MachineMapping const &);

bool nodes_are_disjoint(MachineMapping const &m1, MachineMapping const &m2);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _FLEXFLOW_COMPILER_MACHINE_MAPPING_DP_CACHE_H
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_DP_CACHE_H

#include "machine_mapping_result.dtg.h"
#include "machine_mapping_state.dtg.h"
#include "utils/optional.h"

namespace FlexFlow {

class MachineMappingCache {
public:
MachineMappingCache() = default;

std::optional<MachineMappingResult> load(MachineMappingState const &) const;
void save(MachineMappingState const &, MachineMappingResult const &);

private:
std::unordered_map<MachineMappingState, MachineMappingResult> cache;
};

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace = "FlexFlow"
name = "MachineMappingContext"
features = [
]

includes = [
"machine_mapping.dtg.h",
"pcg/parallel_computation_graph/parallel_computation_graph.h",
"compiler/cost_estimator.h",
"pcg/machine_view.h",
"pcg/machine_specification.dtg.h",
"compiler/machine_mapping/machine_mapping_cache.h"
]

[[fields]]
name = "pcg"
type = "::FlexFlow::ParallelComputationGraph"

[[fields]]
name = "cost_estimator"
type = "::FlexFlow::CostEstimator"

[[fields]]
name = "allowed_machine_views"
type = "std::function<std::unordered_set<::FlexFlow::MachineView>(::FlexFlow::ParallelLayerAttrs const &, ::FlexFlow::MachineSpecification const &)>"

[[fields]]
name = "cached_subgraph_results"
type = "::FlexFlow::MachineMappingCache"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _FLEXFLOW_COMPILER_MACHINE_MAPPING_MACHINE_MAPPING_RESULT_H
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_MACHINE_MAPPING_RESULT_H

#include "machine_mapping_result.dtg.h"

namespace FlexFlow {

MachineMappingResult sequential_combine(MachineMappingResult const &s1,
MachineMappingResult const &s2);
MachineMappingResult parallel_combine(MachineMappingResult const &s1,
MachineMappingResult const &s2);
MachineMappingResult get_infinity_machine_mapping_result();

void minimize_runtime(MachineMappingResult &m1, MachineMappingResult const &m2);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace = "FlexFlow"
name = "MachineMappingResult"
features = [
"eq",
"fmt",
]

includes = [
"machine_mapping.dtg.h",
]

[[fields]]
name = "runtime"
type = "float"

[[fields]]
name = "machine_mapping"
type = "::FlexFlow::MachineMapping"
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace = "FlexFlow"
name = "OptimalCostState"
name = "MachineMappingState"
features = [
"eq",
# "ord",
"hash",
# "json",
# "rapidcheck",
"fmt",
]

includes = [
"utils/graph/serial_parallel/serial_parallel_decomposition.dtg.h",
"pcg/machine_specification.dtg.h",
"pcg/machine_view.dtg.h",
"utils/graph/node/node.dtg.h",
"utils/graph/open_dataflow_graph/open_dataflow_edge.dtg.h",
"utils/fmt/unordered_map.h",
"utils/hash/unordered_map.h",
"utils/graph/open_dataflow_graph/open_dataflow_value.dtg.h",
]

src_includes = [
"utils/hash/unordered_map.h",
"utils/fmt/unordered_map.h",
]

[[fields]]
Expand All @@ -28,9 +28,5 @@ name = "resource"
type = "::FlexFlow::MachineSpecification"

[[fields]]
name = "given_machine_views"
type = "std::unordered_map<::FlexFlow::Node, ::FlexFlow::MachineView>"

[[fields]]
name = "frontier_machine_views"
type = "std::unordered_map<::FlexFlow::OpenDataflowEdge, ::FlexFlow::MachineView>"
name = "fixed_machine_views"
type = "std::unordered_map<::FlexFlow::OpenDataflowValue, ::FlexFlow::MachineView>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _FLEXFLOW_COMPILER_MACHINE_MAPPING_SPLIT_SP_DECOMPOSITION_H
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_SPLIT_SP_DECOMPOSITION_H

#include "utils/graph/serial_parallel/serial_parallel_decomposition.dtg.h"

namespace FlexFlow {

std::pair<SerialParallelDecomposition, SerialParallelDecomposition>
split_sp_decomposition(SerialSplit const &serial);

std::pair<SerialParallelDecomposition, SerialParallelDecomposition>
split_sp_decomposition(ParallelSplit const &parallel);

}

#endif
Loading
Loading