Skip to content

Commit

Permalink
A lot of simplifying and modularizing of unity dp code
Browse files Browse the repository at this point in the history
  • Loading branch information
lockshaw committed Sep 26, 2024
1 parent a112225 commit 3a35951
Show file tree
Hide file tree
Showing 105 changed files with 2,370 additions and 939 deletions.
8 changes: 4 additions & 4 deletions .proj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ test_targets = [
"utils-tests",
"op-attrs-tests",
"pcg-tests",
"substitutions-tests",
# "substitutions-tests",
"compiler-tests",
"substitution-generator-tests",
"local-execution-tests",
"models-tests",
# "substitution-generator-tests",
# "local-execution-tests",
# "models-tests",
]

[cmake_flags_extra]
Expand Down
25 changes: 25 additions & 0 deletions lib/compiler/include/compiler/comm_cost_estimate_key.struct.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace = "FlexFlow"
name = "CommCostEstimateKey"
features = [
"eq",
"ord",
"hash",
"fmt",
]

includes = [
"op-attrs/parallel_tensor_shape.dtg.h",
"pcg/machine_view.dtg.h",
]

[[fields]]
name = "parallel_tensor_shape"
type = "::FlexFlow::ParallelTensorShape"

[[fields]]
name = "src_machine_view"
type = "::FlexFlow::MachineView"

[[fields]]
name = "dst_machine_view"
type = "::FlexFlow::MachineView"
21 changes: 10 additions & 11 deletions lib/compiler/include/compiler/cost_estimator.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_COST_ESTIMATOR_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_COST_ESTIMATOR_H

#ifndef _FLEXFLOW_COMPILER_COST_ESTIMATE_H
#define _FLEXFLOW_COMPILER_COST_ESTIMATE_H

#include "op-attrs/operator_attrs.h"
#include "op-attrs/parallel_tensor_shape.h"
#include "pcg/machine_view.h"
#include "pcg/parallel_computation_graph/parallel_tensor_attrs.dtg.h"
#include <vector>
#include "op-attrs/parallel_tensor_shape.dtg.h"
#include "op-attrs/pcg_operator_attrs.dtg.h"
#include "pcg/machine_view.dtg.h"

namespace FlexFlow {

struct ICostEstimator {
virtual float estimate_cost(PCGOperatorAttrs const &op,
std::vector<ParallelTensorShape> const &inputs,
std::vector<ParallelTensorAttrs> const &weights,
std::vector<ParallelTensorAttrs> const &outputs,
std::vector<ParallelTensorShape> const &weights,
std::vector<ParallelTensorShape> const &outputs,
MachineView const &mv) const = 0;
virtual float estimate_cost(ParallelTensorShape const &tensor_shape,
MachineView const &src,
Expand All @@ -30,8 +29,8 @@ CHECK_RC_COPY_VIRTUAL_COMPLIANT(ICostEstimator);
struct CostEstimator {
float estimate_cost(PCGOperatorAttrs const &op,
std::vector<ParallelTensorShape> const &inputs,
std::vector<ParallelTensorAttrs> const &weights,
std::vector<ParallelTensorAttrs> const &outputs,
std::vector<ParallelTensorShape> const &weights,
std::vector<ParallelTensorShape> const &outputs,
MachineView const &mv) const {
return this->implementation_ptr->estimate_cost(
op, inputs, weights, outputs, mv);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_ESTIMATE_COST_ACROSS_SPLIT_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_ESTIMATE_COST_ACROSS_SPLIT_H

#include "compiler/cost_estimator.h"
#include "compiler/machine_mapping/transitive_reduced_pcg.dtg.h"
#include "pcg/machine_view.dtg.h"
#include "pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h"

namespace FlexFlow {

float estimate_cost_across_split(TransitiveReducedPCG const &,
CostEstimator const &,
std::unordered_map<parallel_layer_guid_t, MachineView> const &,
std::unordered_map<parallel_layer_guid_t, MachineView> const &);

} // namespace FlexFlow

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

#include "compiler/cost_estimator.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.dtg.h"
#include "pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h"
namespace FlexFlow {

float estimate_layer_cost(ParallelComputationGraph const &pcg,
CostEstimator const &cost_estimator,
parallel_layer_guid_t const &layer,
MachineView const &machine_view);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "compiler/machine_mapping/machine_mapping_context.dtg.h"
#include "pcg/machine_specification.dtg.h"
#include "pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h"
#include "pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h"
#include <vector>

namespace FlexFlow {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_GET_MACHINE_RESOURCE_SPLITS_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_GET_MACHINE_RESOURCE_SPLITS_H

#include "pcg/machine_specification.dtg.h"
#include <utility>
#include <unordered_set>

namespace FlexFlow {

std::unordered_set<std::pair<MachineSpecification, MachineSpecification>>
get_machine_resource_splits(MachineSpecification const &resource);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "compiler/machine_mapping/machine_mapping.h"
#include "compiler/machine_mapping/machine_mapping_cache.h"
#include "compiler/machine_mapping/machine_mapping_context.dtg.h"
#include "compiler/machine_mapping/partial_machine_mapping.dtg.h"
#include "compiler/series_parallel/pcg_binary_parallel_split.dtg.h"
#include "compiler/series_parallel/pcg_binary_series_split.dtg.h"
#include "pcg/machine_specification.h"
#include "pcg/machine_view.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph.h"
Expand All @@ -21,36 +24,37 @@ MachineMappingResult get_optimal_machine_mapping(
MachineMappingCache &cached_subgraph_results);

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

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
SerialParallelDecomposition const &decompn,
MachineSpecification const &resource,
std::unordered_map<parallel_tensor_guid_t, MachineView> const
&fixed_machine_views);
MachineMappingCache &result_cache,
MachineMappingContext const &context,
PCGBinarySPDecomposition const &sp_decomposition,
MachineSpecification const &resources,
PartialMachineMapping const &);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
SerialSplit const &serial,
MachineSpecification const &resource,
std::unordered_map<parallel_tensor_guid_t, MachineView> const
&fixed_machine_views);
MachineMappingCache &result_cache,
MachineMappingContext const &context,
PCGBinarySeriesSplit const &series,
MachineSpecification const &resources,
PartialMachineMapping const &);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
ParallelSplit const &parallel,
MachineSpecification const &resource,
std::unordered_map<parallel_tensor_guid_t, MachineView> const
&fixed_machine_views);
MachineMappingCache &result_cache,
MachineMappingContext const &context,
PCGBinaryParallelSplit const &parallel,
MachineSpecification const &resources,
PartialMachineMapping const &);

MachineMappingResult get_optimal_machine_mapping_internal(
MachineMappingContext &context,
Node const &node,
MachineSpecification const &resource,
std::unordered_map<parallel_tensor_guid_t, MachineView> const
&fixed_machine_views);
MachineMappingCache &result_cache,
MachineMappingContext const &,
parallel_layer_guid_t const &,
MachineSpecification const &,
PartialMachineMapping const &);

} // namespace FlexFlow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ src_includes = [

[[fields]]
name = "machine_views"
type = "std::unordered_map<::FlexFlow::parallel_layer_guid_t, ::FlexFlow::MachineView>"
type = "std::unordered_map<::FlexFlow::parallel_layer_guid_t, ::FlexFlow::MachineView>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_MACHINE_MAPPING_CONTEXT_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_MACHINE_MAPPING_CONTEXT_H

#include "compiler/machine_mapping/machine_mapping_context.dtg.h"
#include "pcg/parallel_computation_graph/parallel_computation_graph_edge.dtg.h"
#include "pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h"
#include "pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h"

namespace FlexFlow {

std::unordered_set<MachineView> get_allowed_machine_views_for_tensor(MachineMappingContext const &,
parallel_tensor_guid_t const &);
std::unordered_set<MachineView> get_allowed_machine_views_for_layer(MachineMappingContext const &,
parallel_layer_guid_t const &);

MachineMappingContext make_machine_mapping_context(ParallelComputationGraph const &pcg,
CostEstimator const &cost_estimator,
std::function<std::unordered_set<MachineView>(
ParallelLayerAttrs const &, MachineSpecification const &)> const &allowed_machine_views);

} // namespace FlexFlow

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

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

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

[[fields]]
name = "cost_estimator"
Expand All @@ -23,7 +20,3 @@ 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
Expand Up @@ -6,6 +6,7 @@
namespace FlexFlow {

MachineMappingResult sequential_combine(MachineMappingResult const &s1,
float comm_cost,
MachineMappingResult const &s2);
MachineMappingResult parallel_combine(MachineMappingResult const &s1,
MachineMappingResult const &s2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace = "FlexFlow"
name = "MachineMappingResult"
features = [
"eq",
"hash",
"fmt",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ features = [
]

includes = [
"utils/graph/serial_parallel/serial_parallel_decomposition.dtg.h",
"pcg/machine_specification.dtg.h",
"pcg/machine_view.dtg.h",
"pcg/parallel_computation_graph/parallel_tensor_guid_t.dtg.h",
]

src_includes = [
"utils/hash/unordered_map.h",
"utils/fmt/unordered_map.h",
"compiler/series_parallel/pcg_binary_sp_decomposition.dtg.h",
"compiler/machine_mapping/partial_machine_mapping.dtg.h",
]

[[fields]]
name = "subgraph"
type = "::FlexFlow::SerialParallelDecomposition"
type = "::FlexFlow::PCGBinarySPDecomposition"

[[fields]]
name = "resource"
type = "::FlexFlow::MachineSpecification"

[[fields]]
name = "fixed_machine_views"
type = "std::unordered_map<::FlexFlow::parallel_tensor_guid_t, ::FlexFlow::MachineView>"
name = "partial_solution"
type = "::FlexFlow::PartialMachineMapping"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_PARTIAL_MACHINE_MAPPING_H
#define _FLEXFLOW_LIB_COMPILER_INCLUDE_COMPILER_MACHINE_MAPPING_PARTIAL_MACHINE_MAPPING_H

#include "compiler/machine_mapping/machine_mapping_context.dtg.h"
#include "compiler/machine_mapping/partial_machine_mapping.dtg.h"

namespace FlexFlow {

PartialMachineMapping get_unconstrained_solution();

PartialMachineMapping get_sub_solution(MachineMappingContext const &ctx,
PartialMachineMapping const &partial_solution,
PCGBinarySPDecomposition const &sub_problem);

PartialMachineMapping with_additional_tensor_machine_views(MachineMappingContext const &ctx,
PartialMachineMapping const &partial_solution,
std::unordered_map<parallel_tensor_guid_t, MachineView> const &additional);

PartialMachineMapping with_additional_layer_machine_views(MachineMappingContext const &ctx,
PartialMachineMapping const &partial_solution,
std::unordered_map<parallel_layer_guid_t, MachineView> const &additional);

} // namespace FlexFlow

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

includes = [
"pcg/parallel_computation_graph/parallel_layer_guid_t.dtg.h",
"pcg/machine_view.dtg.h",
]

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

[[fields]]
name = "machine_views"
type = "std::unordered_map<::FlexFlow::parallel_layer_guid_t, ::FlexFlow::MachineView>"

This file was deleted.

Loading

0 comments on commit 3a35951

Please sign in to comment.