Skip to content
Permalink
Browse files

Refactor Optimizer lib into {Graph,IR}Optimizer libs (#3165)

Summary:
Allow for more precise dependences on libs. Most places rely on either the Graph or IR Optimizer, not both. Related to #3161.
Pull Request resolved: #3165

Test Plan: All tests pass.

Reviewed By: bertmaher

Differential Revision: D15979435

Pulled By: jfix71

fbshipit-source-id: 79b96cc791c25c06305c66e1bb0e52aa64ebff3e
  • Loading branch information...
jfix71 authored and facebook-github-bot committed Jun 26, 2019
1 parent 35b41fa commit 3ebf8372a8566576f8d15a06157ae3d2837d99f4
Showing with 157 additions and 107 deletions.
  1. +5 −6 examples/CMakeLists.txt
  2. +1 −0 examples/char-rnn.cpp
  3. +1 −0 examples/fr2en.cpp
  4. +2 −1 examples/mnist.cpp
  5. +1 −1 examples/tracing-compare.cpp
  6. +1 −1 examples/training/resnet50/CMakeLists.txt
  7. +1 −1 examples/training/resnet50/main.cpp
  8. +1 −1 include/glow/Backend/Backend.h
  9. +0 −1 include/glow/ExecutionEngine/ExecutionEngine.h
  10. +3 −3 include/glow/Optimizer/{ → GraphOptimizer}/CompilationContext.h
  11. +3 −3 include/glow/Optimizer/{ → GraphOptimizer}/FunctionPass.h
  12. 0 include/glow/Optimizer/{ → GraphOptimizer}/FunctionPasses.def
  13. +4 −4 include/glow/Optimizer/{ → GraphOptimizer}/FunctionPasses.h
  14. +4 −15 include/glow/Optimizer/{Optimizer.h → GraphOptimizer/GraphOptimizer.h}
  15. +3 −3 include/glow/Optimizer/{ → GraphOptimizer}/TrainingPreparation.h
  16. +39 −0 include/glow/Optimizer/IROptimizer/IROptimizer.h
  17. +2 −0 lib/Backend/Backend.cpp
  18. +1 −3 lib/Backends/CMakeLists.txt
  19. +1 −1 lib/Backends/CPU/CMakeLists.txt
  20. +0 −1 lib/Backends/Habana/CMakeLists.txt
  21. +1 −1 lib/Backends/Interpreter/CMakeLists.txt
  22. +1 −0 lib/Backends/Interpreter/Interpreter.cpp
  23. +1 −1 lib/Backends/OpenCL/CMakeLists.txt
  24. +1 −0 lib/Backends/OpenCL/OpenCL.cpp
  25. +1 −1 lib/ExecutionEngine/CMakeLists.txt
  26. +1 −1 lib/ExecutionEngine/ExecutionEngine.cpp
  27. +1 −1 lib/LLVMIRCodeGen/CMakeLists.txt
  28. +1 −0 lib/LLVMIRCodeGen/LLVMBackend.cpp
  29. +2 −1 lib/Onnxifi/Base.cpp
  30. +2 −2 lib/Onnxifi/CMakeLists.txt
  31. +1 −0 lib/Onnxifi/InlineOnnxifi.cpp
  32. +2 −14 lib/Optimizer/CMakeLists.txt
  33. +13 −0 lib/Optimizer/GraphOptimizer/CMakeLists.txt
  34. +3 −2 lib/Optimizer/{ → GraphOptimizer}/GraphOptimizer.cpp
  35. +2 −2 lib/Optimizer/{ → GraphOptimizer}/Lower.cpp
  36. +1 −1 lib/Optimizer/{ → GraphOptimizer}/Quantization.cpp
  37. +2 −1 lib/Optimizer/{ → GraphOptimizer}/TrainingPreparation.cpp
  38. +8 −0 lib/Optimizer/IROptimizer/CMakeLists.txt
  39. +2 −1 lib/Optimizer/{ → IROptimizer}/IROptimizer.cpp
  40. +4 −3 lib/Partitioner/CMakeLists.txt
  41. +1 −0 lib/Partitioner/Partitioner.cpp
  42. +1 −1 lib/Runtime/HostManager/CMakeLists.txt
  43. +1 −1 lib/Runtime/HostManager/HostManager.cpp
  44. +1 −1 tests/benchmark/CMakeLists.txt
  45. +1 −1 tests/benchmark/RuntimeBench.cpp
  46. +1 −1 tests/stress/CMakeLists.txt
  47. +1 −0 tests/stress/ParameterSweepTest.cpp
  48. +1 −0 tests/unittests/BackendTestUtils.cpp
  49. +12 −17 tests/unittests/CMakeLists.txt
  50. +1 −1 tests/unittests/DeviceManagerTest.cpp
  51. +1 −1 tests/unittests/GraphOptzTest.cpp
  52. +1 −0 tests/unittests/GraphTest.cpp
  53. +1 −1 tests/unittests/HabanaBackendTest.cpp
  54. +1 −1 tests/unittests/IROptTest.cpp
  55. +1 −0 tests/unittests/OperatorTest.cpp
  56. +1 −0 tests/unittests/ProvisionerTest.cpp
  57. +1 −0 tests/unittests/QuantizationTest.cpp
  58. +1 −1 tests/unittests/TraceEventsTest.cpp
  59. +1 −0 tests/unittests/TypeAToTypeBFunctionConverterTest.cpp
  60. +3 −3 tools/loader/CMakeLists.txt
  61. +1 −0 tools/loader/Loader.cpp
@@ -18,7 +18,7 @@ target_link_libraries(mnist
Graph
Importer
IR
Optimizer
GraphOptimizer
Support
LLVMSupport)

@@ -41,7 +41,7 @@ target_link_libraries(char-rnn
ExecutionEngine
Graph
IR
Optimizer
GraphOptimizer
Support)

add_executable(fr2en
@@ -51,7 +51,7 @@ target_link_libraries(fr2en
Base
ExecutionEngine
IR
Optimizer
GraphOptimizer
Quantization
Support
LLVMSupport)
@@ -84,8 +84,7 @@ if(GLOW_WITH_CPU)
HostManager
Partitioner
Graph
Importer
Optimizer)
Importer)
target_include_directories(resnet-runtime PUBLIC ${CMAKE_SOURCE_DIR}/lib)

add_executable(tracing-compare
@@ -97,7 +96,7 @@ if(GLOW_WITH_CPU)
ExecutionEngine
Graph
Importer
Optimizer)
GraphOptimizer)
endif()


@@ -16,6 +16,7 @@
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/IR/IR.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
#include "glow/Support/Support.h"

#include "llvm/Support/CommandLine.h"
@@ -15,6 +15,7 @@
*/
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
#include "glow/Quantization/Quantization.h"
#include "glow/Quantization/Serialization.h"

@@ -17,7 +17,8 @@
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Optimizer/TrainingPreparation.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
#include "glow/Optimizer/GraphOptimizer/TrainingPreparation.h"
#include "glow/Support/Support.h"

#include "llvm/Support/CommandLine.h"
@@ -19,7 +19,7 @@
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Optimizer/Optimizer.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
#include "glow/Runtime/RuntimeTypes.h"

#include "llvm/Support/CommandLine.h"
@@ -5,4 +5,4 @@ target_link_libraries(resnet-training
ExecutionEngine
Graph
Importer
Optimizer)
GraphOptimizer)
@@ -18,7 +18,7 @@
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Nodes.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Optimizer/TrainingPreparation.h"
#include "glow/Optimizer/GraphOptimizer/TrainingPreparation.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Timer.h"
@@ -19,7 +19,7 @@
#include "glow/Backend/CompiledFunction.h"
#include "glow/Backends/BackendOptions.h"
#include "glow/Base/Traits.h"
#include "glow/Optimizer/Optimizer.h"
#include "glow/Optimizer/GraphOptimizer/CompilationContext.h"
#include "glow/Support/Register.h"

#include "llvm/ADT/StringRef.h"
@@ -23,7 +23,6 @@
#include "glow/Base/Traits.h"
#include "glow/Graph/Graph.h"
#include "glow/Graph/PlaceholderBindings.h"
#include "glow/Optimizer/Optimizer.h"

#include "llvm/ADT/ArrayRef.h"

@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOW_OPTIMIZER_COMPILATIONCONTEXT_H
#define GLOW_OPTIMIZER_COMPILATIONCONTEXT_H
#ifndef GLOW_OPTIMIZER_GRAPHOPTIMIZER_COMPILATIONCONTEXT_H
#define GLOW_OPTIMIZER_GRAPHOPTIMIZER_COMPILATIONCONTEXT_H

#include "glow/Backends/BackendOptions.h"
#include "glow/Graph/PlaceholderBindings.h"
@@ -109,4 +109,4 @@ using CompilationMode = CompilationContext::CompilationMode;

}; // namespace glow

#endif // GLOW_OPTIMIZER_COMPILATIONCONTEXT_H
#endif // GLOW_OPTIMIZER_GRAPHOPTIMIZER_COMPILATIONCONTEXT_H
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOW_OPTIMIZER_FUNCTIONPASS_H
#define GLOW_OPTIMIZER_FUNCTIONPASS_H
#ifndef GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASS_H
#define GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASS_H

namespace glow {

@@ -37,4 +37,4 @@ class FunctionPass {

} // namespace glow

#endif // GLOW_OPTIMIZER_FUNCTIONPASS_H
#endif // GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASS_H
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOW_OPTIMIZER_FUNCTIONPASSES_H
#define GLOW_OPTIMIZER_FUNCTIONPASSES_H
#ifndef GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASSES_H
#define GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASSES_H

#include "glow/Optimizer/FunctionPass.h"
#include "glow/Optimizer/GraphOptimizer/FunctionPass.h"

namespace glow {

@@ -31,4 +31,4 @@ namespace glow {

} // namespace glow

#endif // GLOW_OPTIMIZER_FUNCTIONPASSES_H
#endif // GLOW_OPTIMIZER_GRAPHOPTIMIZER_FUNCTIONPASSES_H
@@ -13,26 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOW_OPTIMIZER_OPTIMIZER_H
#define GLOW_OPTIMIZER_OPTIMIZER_H
#ifndef GLOW_OPTIMIZER_GRAPHOPTIMIZER_GRAPHOPTIMIZER_H
#define GLOW_OPTIMIZER_GRAPHOPTIMIZER_GRAPHOPTIMIZER_H

#include "glow/Optimizer/CompilationContext.h"
#include "glow/Optimizer/GraphOptimizer/CompilationContext.h"
#include "glow/Support/Error.h"

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"

namespace glow {

class IRFunction;
class Function;
class Backend;
class Module;
class PlaceholderBindings;
class Placeholder;

/// Perform optimizations on the IR representation.
void optimize(IRFunction &M, bool shouldShareBuffers);
/// Perform optimizations on the graph representation.
void optimize(Function *F, CompilationContext &cctx);
void optimize(Function *F, CompilationMode mode);
@@ -61,13 +57,6 @@ void convertPlaceholdersToConstants(Function *F,
/// in context \p bindings.
void profileQuantization(PlaceholderBindings &bindings, Function *F);

/// Helper to generate and optimize IR from given Function \p F. \p
/// shouldShareBuffers signifies whether to use the share buffers optimization.
/// Backend /p B is used to allow for custom lowering from Node to
/// Instruction IR.
std::unique_ptr<IRFunction> generateAndOptimizeIR(Function *F, const Backend &B,
bool shouldShareBuffers);

/// Optimize the Function \p F given compilation options \p cctx for Backend \B.
/// \returns success if all nodes in the final resulting optimized Function are
/// supported by \p B; if not, this represents a compiler error.
@@ -82,4 +71,4 @@ llvm::Error optimizeFunctionBeforeLowering(Function *F,
CompilationContext &cctx);
} // namespace glow

#endif // GLOW_OPTIMIZER_OPTIMIZER_H
#endif // GLOW_OPTIMIZER_GRAPHOPTIMIZER_GRAPHOPTIMIZER_H
@@ -14,8 +14,8 @@
* limitations under the License.
*/

#ifndef GLOW_OPTIMIZER_TRAININGPREPARATION_H
#define GLOW_OPTIMIZER_TRAININGPREPARATION_H
#ifndef GLOW_OPTIMIZER_GRAPHOPTIMIZER_TRAININGPREPARATION_H
#define GLOW_OPTIMIZER_GRAPHOPTIMIZER_TRAININGPREPARATION_H

#include "glow/Graph/Graph.h"
#include "glow/Support/Error.h"
@@ -43,4 +43,4 @@ llvm::Error prepareFunctionForTraining(
TensorInitializer &&initializer = getDefaultTensorInitializer());
} // namespace glow

#endif // GLOW_OPTIMIZER_TRAININGPREPARATION_H
#endif // GLOW_OPTIMIZER_GRAPHOPTIMIZER_TRAININGPREPARATION_H
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOW_OPTIMIZER_IROPTIMIZER_IROPTIMIZER_H
#define GLOW_OPTIMIZER_IROPTIMIZER_IROPTIMIZER_H

#include <memory>

namespace glow {

class IRFunction;
class Function;
class Backend;

/// Perform optimizations on the IR representation.
void optimize(IRFunction &M, bool shouldShareBuffers);

/// Helper to generate and optimize IR from given Function \p F. \p
/// shouldShareBuffers signifies whether to use the share buffers optimization.
/// Backend /p B is used to allow for custom lowering from Node to
/// Instruction IR.
std::unique_ptr<IRFunction> generateAndOptimizeIR(Function *F, const Backend &B,
bool shouldShareBuffers);

} // namespace glow

#endif // GLOW_OPTIMIZER_IROPTIMIZER_IROPTIMIZER_H
@@ -15,9 +15,11 @@
*/

#include "glow/Backend/Backend.h"

#include "glow/Graph/Graph.h"
#include "glow/Graph/PlaceholderBindings.h"
#include "glow/IR/Instrs.h"
#include "glow/Optimizer/GraphOptimizer/CompilationContext.h"

using namespace glow;

@@ -29,9 +29,7 @@ target_link_libraries(Backends
PRIVATE
Backend
Base
Graph
Graph
Optimizer)
Graph)

FOREACH(backend ${linked_backends})
make_whole_archive(Backends ${backend})
@@ -88,7 +88,7 @@ target_link_libraries(CPUBackend
CodeGen
Graph
IR
Optimizer
IROptimizer
QuantizationBase
LLVMIRCodeGen)
add_dependencies(CPUBackend CPURuntime)
@@ -18,7 +18,6 @@ target_link_libraries(Habana
CodeGen
IR
LLVMCore
Optimizer
QuantizationBase
Support)

@@ -12,7 +12,7 @@ target_link_libraries(Interpreter
Graph
IR
LLVMCore
Optimizer
IROptimizer
QuantizationBase)

set(linked_backends ${linked_backends} Interpreter PARENT_SCOPE)
@@ -22,6 +22,7 @@
#include "glow/Graph/Graph.h"
#include "glow/Graph/Nodes.h"
#include "glow/IR/IR.h"
#include "glow/Optimizer/IROptimizer/IROptimizer.h"

using namespace glow;

@@ -46,7 +46,7 @@ target_link_libraries(OpenCLBackend
CodeGen
IR
LLVMCore
Optimizer
IROptimizer
QuantizationBase)

target_link_libraries(OpenCLBackend
@@ -28,6 +28,7 @@
#include "glow/Graph/Nodes.h"
#include "glow/IR/IRUtils.h"
#include "glow/IR/Instrs.h"
#include "glow/Optimizer/IROptimizer/IROptimizer.h"
#include "glow/Quantization/Base/Base.h"
#include "glow/Support/Debug.h"

@@ -5,6 +5,6 @@ target_link_libraries(ExecutionEngine
PRIVATE
Backend
Backends
Optimizer
GraphOptimizer
Base
Graph)
@@ -18,7 +18,7 @@
#include "glow/Backend/Backend.h"
#include "glow/Graph/Graph.h"
#include "glow/Graph/PlaceholderBindings.h"
#include "glow/Optimizer/Optimizer.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"

#include "llvm/ADT/STLExtras.h"

@@ -18,7 +18,7 @@ target_link_libraries(LLVMIRCodeGen
CodeGen
Graph
IR
Optimizer
IROptimizer
QuantizationBase
${LLVM_TARGET_LIBRARIES}
LLVMAnalysis
@@ -23,6 +23,7 @@
#include "glow/Graph/Graph.h"
#include "glow/Graph/PlaceholderBindings.h"
#include "glow/IR/Instrs.h"
#include "glow/Optimizer/IROptimizer/IROptimizer.h"
#include "glow/Support/Debug.h"

#include "llvm/ADT/STLExtras.h"
@@ -16,7 +16,8 @@
#include "Base.h"

#include "glow/Importer/ONNXIFIModelLoader.h"
#include "glow/Optimizer/FunctionPasses.h"
#include "glow/Optimizer/GraphOptimizer/FunctionPasses.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"

#include "llvm/Support/Format.h"
#include <glog/logging.h>

0 comments on commit 3ebf837

Please sign in to comment.
You can’t perform that action at this time.