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 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 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"

namespace FlexFlow {

Expand All @@ -10,6 +12,9 @@ MachineMapping combine_disjoint_mappings(MachineMapping const &,

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

MachineMapping get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &, MachineMappingResult const &);

} // 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
21 changes: 21 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,21 @@
#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,
DeviceType device_type);

} // 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
31 changes: 31 additions & 0 deletions lib/compiler/src/compiler/compiler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "compiler/compiler.h"
#include "compiler/unity_algorithm/unity_algorithm.h"
#include "utils/overload.h"

namespace FlexFlow {

SearchResult optimize(ComputationGraph const &computation_graph,
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");
},
[&](UnitySearchConfig const &config) {
ParallelComputationGraph pcg =
parallel_computation_graph_from_computation_graph(computation_graph);
std::vector<Substitution> substitutions; // TODO: Implement this
return graph_optimize(pcg,
cost_estimator,
machine_specification,
substitutions,
config,
DeviceType::GPU);

},
});
}

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

This file was deleted.

37 changes: 37 additions & 0 deletions lib/compiler/src/compiler/machine_mapping/machine_mapping.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "compiler/machine_mapping/machine_mapping.h"
#include "compiler/series_parallel/pcg/pcg_binary_sp_decomposition.h"
#include "utils/containers/are_disjoint.h"
#include "utils/containers/keys.h"
#include "utils/containers/merge_maps.h"
#include "utils/containers/map_keys.h"
#include "utils/graph/series_parallel/binary_sp_decomposition_tree/binary_sp_decomposition_tree.h"

namespace FlexFlow {

Expand All @@ -14,4 +17,38 @@ bool nodes_are_disjoint(MachineMapping const &m1, MachineMapping const &m2) {
return are_disjoint(keys(m1.machine_views), keys(m2.machine_views));
}

MachineMapping get_machine_mapping_from_machine_mapping_result(
PCGBinarySPDecomposition const &sp_decomposition,
MachineMappingResult const &mm_result) {

BinarySPDecompositionTree sp_tree =
binary_sp_tree_from_pcg_sp_tree(sp_decomposition);

auto get_layer_from_path =
[&](BinaryTreePath const &path) -> parallel_layer_guid_t {
std::optional<BinarySPDecompositionTree> subtree_optional =
binary_sp_decomposition_tree_get_subtree_at_path(sp_tree, path);
if (!subtree_optional.has_value()) {
throw std::runtime_error(fmt::format("Invalid tree path {}", path));
}
BinarySPDecompositionTree subtree = subtree_optional.value();
if (!subtree.is_node()) {
throw std::runtime_error(fmt::format("Invalid tree path to a leaf: found {} instead", subtree));
}
return parallel_layer_guid_t{
subtree.require_node(),
};
};

std::unordered_map<parallel_layer_guid_t, MachineView> mm;

if (mm_result.raw_result) {
FeasibleMachineMappingResult const &feasible_mm_result =
mm_result.raw_result.value();
mm = map_keys(feasible_mm_result.machine_mapping.raw_mapping, get_layer_from_path);
}

return MachineMapping{mm};
}

} // namespace FlexFlow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "compiler/allowed_machine_views.h"
#include "compiler/unity_algorithm/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