Skip to content

Commit

Permalink
Resurrect substitution-to-dot (#1351)
Browse files Browse the repository at this point in the history
* Add initial lib/substitution-generator and bin/substitutions-to-dot

* Format
  • Loading branch information
lockshaw authored May 23, 2024
1 parent 6a3abdf commit 7723449
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/per-lib-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
run: |
build_libs.sh compiler
- name: Build substitution-generator
run: |
build_libs.sh substitution-generator
- name: Test utils
run: |
test_libs.sh utils
Expand All @@ -91,3 +95,7 @@ jobs:
- name: Test compiler
run: |
test_libs.sh compiler
- name: Test substitution-generator
run: |
test_libs.sh substitution-generator
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ option(FF_BUILD_SPLIT_TEST_2 "build split test 2 example" OFF)
option(FF_BUILD_ALL_EXAMPLES "build all examples. Overrides others" OFF)
option(FF_BUILD_UNIT_TESTS "build non-operator unit tests" OFF)
option(FF_BUILD_SUBSTITUTION_TOOL "build substitution conversion tool" OFF)
option(FF_BUILD_VISUALIZATION_TOOL "build substitution visualization tool" OFF)
option(FF_BUILD_VISUALIZATION_TOOL "build substitution visualization tool" ON)
option(FF_BUILD_ARG_PARSER "build command line argument parser" OFF)

set(FF_CUDA_ARCH "autodetect" CACHE STRING "Target CUDA Arch")
Expand Down
2 changes: 1 addition & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(FF_BUILD_SUBSTITUTION_TOOL)
endif()

if(FF_BUILD_VISUALIZATION_TOOL)
add_subdirectory(substitutions_to_dot)
add_subdirectory(substitutions-to-dot)
endif()

if(FF_BUILD_ARG_PARSER)
Expand Down
8 changes: 8 additions & 0 deletions bin/substitutions-to-dot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ff_add_executable(
NAME
substitution-to-dot
SRC_PATTERNS
*.cc
DEPS
substitution-generator
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "ffc/substitution_loader.h"
#include "op-meta/ffconst.h"
#include "tl/optional.hpp"
#include "substitution-generator/json.h"
#include "utils/dot_file.h"
#include <cassert>
#include <iostream>

using namespace FlexFlow::substitution_loader;
using FlexFlow::opmeta::get_operator_type_name;
using namespace FlexFlow;

enum class NodeType {
SRC,
Expand All @@ -29,7 +26,7 @@ int main(int argc, char **argv) {

RuleCollection rule_collection = load_rule_collection_from_path(json_path);

tl::optional<Rule> found = tl::nullopt;
std::optional<Rule> found = std::nullopt;
for (Rule const &r : rule_collection.rules) {
if (r.name == rule_name) {
found = r;
Expand Down Expand Up @@ -88,10 +85,7 @@ int main(int argc, char **argv) {
Operator const &o = r.srcOp[i];
Node srcOpNode = {NodeType::SRC, i, 0};
{
dot.add_node(
srcOpNode,
label_map(FlexFlow::opmeta::get_operator_type_name(o.op_type),
srcOpNode));
dot.add_node(srcOpNode, label_map(fmt::to_string(o.op_type), srcOpNode));
dot.add_node_to_subgraph(srcOpNode, src_body_subgraph);
}

Expand All @@ -115,10 +109,7 @@ int main(int argc, char **argv) {
Operator const &o = r.dstOp[j];
Node dstOpNode = {NodeType::DST, j, 0};
{
dot.add_node(
dstOpNode,
label_map(FlexFlow::opmeta::get_operator_type_name(o.op_type),
dstOpNode));
dot.add_node(dstOpNode, label_map(fmt::to_string(o.op_type), dstOpNode));
dot.add_node_to_subgraph(dstOpNode, dst_body_subgraph);
}

Expand Down
12 changes: 0 additions & 12 deletions bin/substitutions_to_dot/CMakeLists.txt

This file was deleted.

32 changes: 32 additions & 0 deletions cmake/flexflow-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,35 @@ function(ff_add_test_executable)
ff_set_cxx_properties(${FF_TEST_EXEC_NAME})
doctest_discover_tests(${FF_TEST_EXEC_NAME} ADD_LABELS 1)
endfunction()

function(ff_add_executable)
ff_parse_args(
PREFIX
FF_EXEC
ARGS
NAME
VARIADIC_ARGS
SRC_PATTERNS
PRIVATE_INCLUDE
DEPS
PARSE
${ARGN}
)

project(${FF_EXEC_NAME})
file(GLOB_RECURSE SRC
CONFIGURE_DEPENDS
LIST_DIRECTORIES False
${FF_EXEC_SRC_PATTERNS})

add_executable(
${FF_EXEC_NAME}
${SRC})

target_link_libraries(
${FF_EXEC_NAME}
${FF_EXEC_DEPS})

define_ff_vars(${FF_EXEC_NAME})
ff_set_cxx_properties(${FF_EXEC_NAME})
endfunction()
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ add_subdirectory(kernels)
add_subdirectory(utils)
add_subdirectory(ffi)
add_subdirectory(substitutions)
add_subdirectory(substitution-generator)
Loading

0 comments on commit 7723449

Please sign in to comment.