Skip to content

Commit

Permalink
Merge branch 'develop' into summary_bug_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrogenSulfate committed Jul 29, 2021
2 parents 9787ed3 + b56dbe0 commit f451623
Show file tree
Hide file tree
Showing 175 changed files with 5,658 additions and 1,412 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ else()
endif()
endif()

if(WITH_DISTRIBUTE)
if(LINUX)
set(WITH_GLOO ON CACHE STRING "Enable GLOO when compiling WITH_DISTRIBUTE=ON." FORCE)
endif()
if(WITH_ASCEND_CL)
# disable WITH_PSCORE for NPU before include third_party
MESSAGE(WARNING "Disable WITH_PSCORE when compiling with NPU. Force WITH_PSCORE=OFF.")
set(WITH_PSCORE OFF CACHE BOOL "Disable WITH_PSCORE when compiling with NPU" FORCE)
endif()
endif()

include(third_party) # download, build, install third_party, Contains about 20+ dependencies

include(flags) # set paddle compile flags
Expand All @@ -324,12 +335,6 @@ if(WITH_PROFILER)
add_definitions(-DWITH_GPERFTOOLS)
endif()

if(WITH_DISTRIBUTE)
if(LINUX)
set(WITH_GLOO ON CACHE STRING "Enable GLOO when compiling WITH_DISTRIBUTE=ON." FORCE)
endif()
endif()

include(ccache) # set ccache for compilation
include(util) # set unittest and link libs
include(version) # set PADDLE_VERSION
Expand Down
6 changes: 1 addition & 5 deletions cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,8 @@ function(generate_dummy_static_lib)
if(NOT dummy_GENERATOR)
message(FATAL_ERROR "You must provide a generator file name.")
endif()
# if ${dummy_GENERATOR} contains "/", it may be a file path
if(NOT ${dummy_GENERATOR} MATCHES ".*/.*")
set(dummy_GENERATOR "${CMAKE_CURRENT_LIST_DIR}/${dummy_GENERATOR}")
endif()
if(NOT dummy_CONTENT)
set(dummy_CONTENT "${dummy_FILE_PATH} for lib ${dummy_LIB_NAME}")
set(dummy_CONTENT "${dummy_LIB_NAME}_dummy.c for lib ${dummy_LIB_NAME}")
endif()

configure_file(${PROJECT_SOURCE_DIR}/cmake/dummy.c.in ${dummy_FILE_PATH} @ONLY)
Expand Down
7 changes: 5 additions & 2 deletions cmake/unity_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ function(compose_unity_target_sources TARGET TYPE)
get_property(unity_group_index_max GLOBAL PROPERTY ${TARGET}_${TYPE}_group_index)
foreach(src ${ARGN})
set(unity_file "")
# UB use absolute path of source.
# Note(zhouwei25): UB use the path releative to CMAKE_SOURCE_DIR.
# If use absolute path, sccache/ccache hit rate will be reduced.
if(IS_ABSOLUTE ${src})
set(src_absolute_path ${src})
file(RELATIVE_PATH src_relative_path ${CMAKE_SOURCE_DIR} ${src})
else()
set(src_absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${src})
file(RELATIVE_PATH src_relative_path ${CMAKE_SOURCE_DIR} ${src_absolute_path})
endif()
# If `unity_group_index_max` is empty, there is no combination
# relationship.
Expand All @@ -106,7 +109,7 @@ function(compose_unity_target_sources TARGET TYPE)
set_property(GLOBAL APPEND PROPERTY ${unity_file_sources} ${UNITY_CU_BEFORE_CODE})
endif()
endif()
set_property(GLOBAL APPEND PROPERTY ${unity_file_sources} "#include \"${src_absolute_path}\"")
set_property(GLOBAL APPEND PROPERTY ${unity_file_sources} "#include \"${src_relative_path}\"")
set(unity_target_sources ${unity_target_sources} ${unity_file})
break()
endif()
Expand Down
70 changes: 50 additions & 20 deletions paddle/fluid/distributed/service/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,65 @@ using Variable = framework::Variable;
template <typename T>
class BlockingQueue {
public:
explicit BlockingQueue(size_t capacity) : capacity_(capacity) {
PADDLE_ENFORCE_GT(capacity_, 0,
platform::errors::InvalidArgument(
"The capacity must be greater than 0."));
}
explicit BlockingQueue(size_t capacity) : capacity_(capacity) {}

bool Push(const T &elem) {
{
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [&] { return queue_.size() < capacity_; });
queue_.push_back(elem);
std::unique_lock<std::mutex> lock(mutex_);
WaitForWrite(lock);

queue_.push_back(elem);

Notify();
return true;
}
bool WaitForWrite(std::unique_lock<std::mutex> &lock) { // NOLINT
while (FullUnlocked()) {
if (empty_waiters_ != 0) {
empty_cond_.notify_one();
}
full_waiters_++;
full_cond_.wait(lock);
full_waiters_--;
}
cv_.notify_one();
return true;
}

bool Push(T &&elem) {
{
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [&] { return queue_.size() < capacity_; });
queue_.emplace_back(std::move(elem));
bool WaitForRead(std::unique_lock<std::mutex> &lock) { // NOLINT
while (EmptyUnlocked()) {
if (full_waiters_ != 0) {
full_cond_.notify_one();
}
empty_waiters_++;
empty_cond_.wait(lock);
empty_waiters_--;
}
cv_.notify_one();
return true;
}
bool EmptyUnlocked() { return queue_.empty(); }

bool FullUnlocked() { return queue_.size() >= capacity_; }
void Notify() {
if (empty_waiters_ != 0 && (!EmptyUnlocked())) {
empty_cond_.notify_one();
}
if (full_waiters_ != 0 && (!FullUnlocked())) {
full_cond_.notify_one();
}
}

bool Push(T &&elem) {
std::unique_lock<std::mutex> lock(mutex_);
WaitForWrite(lock);
queue_.emplace_back(std::move(elem));

Notify();
return true;
}
T Pop() {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [=] { return !queue_.empty(); });
WaitForRead(lock);
T rc(std::move(queue_.front()));
queue_.pop_front();
cv_.notify_one();
Notify();
return rc;
}

Expand All @@ -107,11 +134,14 @@ class BlockingQueue {
}

private:
int empty_waiters_ = 0;
int full_waiters_ = 0;
std::condition_variable empty_cond_;
std::condition_variable full_cond_;
const size_t capacity_;
std::deque<T> queue_;

mutable std::mutex mutex_;
std::condition_variable cv_;
};

template <typename T, int MajorType = Eigen::RowMajor,
Expand Down
4 changes: 3 additions & 1 deletion paddle/fluid/framework/details/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ set(IR_PASS_DEPS graph_viz_pass multi_devices_graph_pass
modify_op_lock_and_record_event_pass
coalesce_grad_tensor_pass fuse_all_reduce_op_pass backward_optimizer_op_deps_pass
fuse_adam_op_pass fuse_sgd_op_pass fuse_momentum_op_pass
sync_batch_norm_pass runtime_context_cache_pass)
sync_batch_norm_pass runtime_context_cache_pass graph_to_program_pass)
if(NOT APPLE AND NOT WIN32 AND (WITH_GPU OR WITH_ROCM))
set(IR_PASS_DEPS ${IR_PASS_DEPS} fusion_group_pass)
endif()
cc_library(build_strategy SRCS build_strategy.cc DEPS pass_builder ${IR_PASS_DEPS})
cc_test(build_strategy_test SRCS build_strategy_test.cc
DEPS build_strategy op_registry op_proto_maker graph)

if (WITH_MKLDNN)
target_link_libraries(build_strategy mkldnn_placement_pass)
Expand Down
15 changes: 14 additions & 1 deletion paddle/fluid/framework/details/build_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License. */
#include "paddle/fluid/framework/ir/multi_devices_graph_pass/multi_devices_graph_pass.h"

DECLARE_bool(use_mkldnn);
DECLARE_bool(convert_all_blocks);

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -312,6 +313,11 @@ ir::Graph *BuildStrategy::Apply(ir::Graph *graph,
DeviceType use_device) const {
#endif
VLOG(1) << "apply all passes";
if (FLAGS_convert_all_blocks) {
PADDLE_ENFORCE_EQ(
graph->IsMainGraph(), true,
platform::errors::InvalidArgument("This graph is not main_graph"));
}
// Create a default one if not finalized by user.
CreatePassesFromStrategy(false);

Expand Down Expand Up @@ -432,7 +438,14 @@ ir::Graph *BuildStrategy::Apply(ir::Graph *graph,
}
}
VLOG(1) << "Start Apply Pass " << pass->Type();
graph = pass->Apply(graph);
if (FLAGS_convert_all_blocks) {
for (size_t i = 0; i < graph->SubGraphsSize(); ++i) {
VLOG(3) << "Apply Pass " << pass->Type() << "to SubGraph " << i;
pass->Apply(graph->GetSubGraph(i));
}
} else {
graph = pass->Apply(graph);
}
VLOG(1) << "Finish Apply Pass " << pass->Type();
}
VLOG(1) << "All Passes Applied";
Expand Down
Loading

0 comments on commit f451623

Please sign in to comment.