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

Top-level loop for compiler #1576

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions lib/compiler/include/compiler/algorithm_config.variant.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace = "FlexFlow"
name = "AlgorithmConfig"
features = [
"eq",
"hash",
"fmt",
]

includes = [
"compiler/data_parallelism/data_parallelism_config.dtg.h",
"compiler/unity_algorithm/unity_search_config.dtg.h",
]

[[values]]
type = "::FlexFlow::DataParallelismConfig"

[[values]]
type = "::FlexFlow::UnitySearchConfig"
32 changes: 6 additions & 26 deletions lib/compiler/include/compiler/compiler.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
#ifndef _FLEXFLOW_COMPILER_COMPILER_H
#define _FLEXFLOW_COMPILER_COMPILER_H

#include "pcg/cost_values.h"
#include "pcg/machine_view.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"
#include "pcg/tensor_mapping.h"
#include "compiler/algorithm_config.dtg.h"
#include "compiler/cost_estimator/cost_estimator.h"
#include "compiler/search_result.dtg.h"
#include "pcg/machine_specification.dtg.h"

namespace FlexFlow {

enum class SearchAlgorithm {
DATA_PARALLEL,
};

using SearchAlgorithmConfig = std::variant<>;
using SearchSolution = std::variant<>;

struct SearchResult {
ParallelComputationGraph pcg;
TensorMapping tensor_mapping;
SearchSolution solution;
CostValues cost_values;
UNITY,
};

SearchResult optimize(ComputationGraph const &,
MachineSpecification const &,
CostEstimator const &,
SearchAlgorithm,
optional<AlgorithmConfig> const &);

// struct SearchSolution {
// LabelledMultiDiGraph<PCGOperatorAttrs, ParallelTensorShape> optimized_pcg;
// std::unordered_map<Node, MachineView> device_assignments;
// /* std::unordered_map<tensor_guid_t,
// std::unordered_set<parallel_tensor_guid_t>> tensor_mappings; */
// };
//
// SearchSolution run_data_parallelize(ComputationGraph const &,
// MachineSpecification const &);
AlgorithmConfig const &);

} // namespace FlexFlow

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace = "FlexFlow"
name = "DataParallelismConfig"
features = [
"eq",
"hash",
"fmt",
]

includes = [
]

[[fields]]
name = "degree"
type = "int"
16 changes: 0 additions & 16 deletions lib/compiler/include/compiler/graph_optimize_result.struct.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define _FLEXFLOW_COMPILER_MACHINE_MAPPING_H

#include "compiler/machine_mapping/machine_mapping.dtg.h"
#include "compiler/machine_mapping/machine_mapping_result.h"
#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.dtg.h"
#include "pcg/device_id_t.dtg.h"
#include "pcg/machine_specification.dtg.h"
#include "pcg/operator_task_space.dtg.h"
Expand All @@ -14,6 +16,13 @@ MachineMapping combine_disjoint_mappings(MachineMapping const &,

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

parallel_layer_guid_t
get_layer_from_path(PCGBinarySPDecomposition const &sp_decomposition,
BinaryTreePath const &path);

std::optional<MachineMapping> get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &, MachineMappingResult const &);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "compiler/machine_mapping/machine_mapping_problem_tree/machine_mapping_problem_tree.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/mm_problem_tree_parallel_split.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/mm_problem_tree_series_split.dtg.h"
#include "compiler/machine_mapping/machine_mapping_problem_tree/unmapped_op_cost_estimate_key.dtg.h"
#include "utils/full_binary_tree/binary_tree_path.dtg.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree/generic_binary_sp_decomposition_tree_implementation.dtg.h"
#include "utils/graph/series_parallel/sp_decomposition_tree_node_type.dtg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ includes = [
"op-attrs/parallel_tensor_shape.dtg.h",
"<vector>",
"pcg/machine_view.dtg.h",
"pcg/operator_task_space.dtg.h",
]

src_includes = [
Expand All @@ -34,3 +35,6 @@ type = "std::vector<::FlexFlow::ParallelTensorShape>"
name = "output_shapes"
type = "std::vector<::FlexFlow::ParallelTensorShape>"

[[fields]]
name = "op_task_space"
type = "::FlexFlow::OperatorTaskSpace"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ FeasibleMachineMappingResult require_feasible(MachineMappingResult const &);
make_singleton_machine_mapping_result(float runtime,
MachineView const &machine_view);

[[nodiscard]] float get_runtime_cost(MachineMappingResult const &mm_result);

} // namespace FlexFlow

#endif
17 changes: 17 additions & 0 deletions lib/compiler/include/compiler/search_result.struct.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace = "FlexFlow"
name = "SearchResult"
features = [
]

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

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

[[fields]]
name = "machine_mapping"
type = "::FlexFlow::MachineMapping"
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_SERIES_PARALLEL_GET_PCG_BALANCED_BINARY_SP_DECOMPOSITION_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_SERIES_PARALLEL_GET_PCG_BALANCED_BINARY_SP_DECOMPOSITION_H

#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.dtg.h"

namespace FlexFlow {

std::optional<PCGBinarySPDecomposition>
Expand Down
24 changes: 0 additions & 24 deletions lib/compiler/include/compiler/unity_algorithm.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef _FLEXFLOW_COMPILER_MCMC_STATE_H
#define _FLEXFLOW_COMPILER_MCMC_STATE_H

#include "compiler/graph_optimize_result.dtg.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"

namespace FlexFlow {

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

GraphOptimizeResult graph_optimize_result;
float runtime;
ParallelComputationGraph pcg;
float runtime_with_optimal_mm;

bool operator==(GraphOptimizeState const &other) const;
bool operator!=(GraphOptimizeState const &other) const;
Expand Down
20 changes: 20 additions & 0 deletions lib/compiler/include/compiler/unity_algorithm/unity_algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _FLEXFLOW_COMPILER_UNITY_ALGORITHM_H
#define _FLEXFLOW_COMPILER_UNITY_ALGORITHM_H

#include "compiler/cost_estimator/cost_estimator.h"
#include "compiler/search_result.dtg.h"
#include "compiler/unity_algorithm/unity_search_config.dtg.h"
#include "pcg/machine_specification.dtg.h"
#include "substitutions/substitution.h"

namespace FlexFlow {

SearchResult graph_optimize(ParallelComputationGraph &pcg,
CostEstimator const &cost_estimator,
MachineSpecification const &resources,
std::vector<Substitution> const &substitutions,
UnitySearchConfig const &search_config);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace = "FlexFlow"
name = "OptimizerConfig"
name = "UnitySearchConfig"
features = [
"eq",
"hash",
Expand Down
27 changes: 27 additions & 0 deletions lib/compiler/src/compiler/compiler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "compiler/compiler.h"
#include "compiler/unity_algorithm/unity_algorithm.h"
#include "pcg/pcg_from_computation_graph.h"
#include "utils/overload.h"

namespace FlexFlow {

SearchResult optimize(ComputationGraph const &computation_graph,

Check warning on line 8 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L8

Added line #L8 was not covered by tests
MachineSpecification const &machine_specification,
CostEstimator const &cost_estimator,
AlgorithmConfig const &search_config) {
return search_config.visit<SearchResult>(overload{
[&](DataParallelismConfig const &config) -> SearchResult {
throw std::runtime_error(
"Data parallel search algorithm is not implemented yet");

Check warning on line 15 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L12-L15

Added lines #L12 - L15 were not covered by tests
},
[&](UnitySearchConfig const &config) {

Check warning on line 17 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L17

Added line #L17 was not covered by tests
ParallelComputationGraph pcg =
pcg_from_computation_graph(computation_graph);
std::vector<Substitution> substitutions; // TODO: Implement this

Check warning on line 20 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L19-L20

Added lines #L19 - L20 were not covered by tests
return graph_optimize(
pcg, cost_estimator, machine_specification, substitutions, config);
},
});

Check warning on line 24 in lib/compiler/src/compiler/compiler.cc

View check run for this annotation

Codecov / codecov/patch

lib/compiler/src/compiler/compiler.cc#L22-L24

Added lines #L22 - L24 were not covered by tests
}

} // namespace FlexFlow
85 changes: 0 additions & 85 deletions lib/compiler/src/compiler/graph_optimize_state.cc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "compiler/allowed_machine_views.h"
#include "compiler/machine_mapping/allowed_machine_views.h"
#include "pcg/machine_specification.h"
#include "pcg/machine_view.h"
#include "pcg/multi_dimensional_stride.dtg.h"
Expand Down
Loading
Loading