commit
e0a89503f8
@ -0,0 +1,46 @@
|
||||
INCLUDE(ExternalProject)
|
||||
|
||||
set(XXHASH_SOURCE_DIR ${THIRD_PARTY_PATH}/xxhash)
|
||||
set(XXHASH_INSTALL_DIR ${THIRD_PARTY_PATH}/install/xxhash)
|
||||
set(XXHASH_INCLUDE_DIR "${XXHASH_INSTALL_DIR}/include")
|
||||
|
||||
IF(WITH_STATIC_LIB)
|
||||
SET(BUILD_CMD make lib)
|
||||
ELSE()
|
||||
SET(BUILD_CMD sed -i "s/-Wstrict-prototypes -Wundef/-Wstrict-prototypes -Wundef -fPIC/g" ${XXHASH_SOURCE_DIR}/src/extern_xxhash/Makefile && make lib)
|
||||
ENDIF()
|
||||
|
||||
ExternalProject_Add(
|
||||
extern_xxhash
|
||||
${EXTERNAL_PROJECT_LOG_ARGS}
|
||||
GIT_REPOSITORY "https://github.com/Cyan4973/xxHash"
|
||||
GIT_TAG "v0.6.5"
|
||||
PREFIX ${XXHASH_SOURCE_DIR}
|
||||
DOWNLOAD_NAME "xxhash"
|
||||
UPDATE_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_IN_SOURCE 1
|
||||
PATCH_COMMAND
|
||||
BUILD_COMMAND ${BUILD_CMD}
|
||||
INSTALL_COMMAND export PREFIX=${XXHASH_INSTALL_DIR}/ && make install
|
||||
TEST_COMMAND ""
|
||||
)
|
||||
|
||||
set(XXHASH_LIBRARIES "${XXHASH_INSTALL_DIR}/lib/libxxhash.a")
|
||||
INCLUDE_DIRECTORIES(${XXHASH_INCLUDE_DIR})
|
||||
|
||||
add_library(xxhash STATIC IMPORTED GLOBAL)
|
||||
set_property(TARGET xxhash PROPERTY IMPORTED_LOCATION ${XXHASH_LIBRARIES})
|
||||
include_directories(${XXHASH_INCLUDE_DIR})
|
||||
add_dependencies(xxhash extern_xxhash)
|
||||
|
||||
LIST(APPEND external_project_dependencies xxhash)
|
||||
|
||||
IF(WITH_C_API)
|
||||
INSTALL(DIRECTORY ${XXHASH_INCLUDE_DIR} DESTINATION third_party/xxhash)
|
||||
IF(ANDROID)
|
||||
INSTALL(FILES ${XXHASH_LIBRARIES} DESTINATION third_party/xxhash/lib/${ANDROID_ABI})
|
||||
ELSE()
|
||||
INSTALL(FILES ${XXHASH_LIBRARIES} DESTINATION third_party/xxhash/lib)
|
||||
ENDIF()
|
||||
ENDIF()
|
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "paddle/fluid/framework/details/fused_broadcast_op_handle.h"
|
||||
#include "paddle/fluid/framework/details/container_cast.h"
|
||||
#include "paddle/fluid/framework/details/variable_visitor.h"
|
||||
#include "paddle/fluid/platform/profiler.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
namespace details {
|
||||
|
||||
void FusedBroadcastOpHandle::RunImpl() {
|
||||
platform::RecordEvent record_event(Name(), dev_ctxes_.begin()->second);
|
||||
|
||||
if (places_.size() == 1UL) return;
|
||||
|
||||
auto in_var_handles = DynamicCast<VarHandle>(inputs_);
|
||||
auto out_var_handles = DynamicCast<VarHandle>(outputs_);
|
||||
|
||||
WaitInputVarGenerated();
|
||||
|
||||
std::vector<const Scope *> var_scopes;
|
||||
for (auto *s : local_scopes_) {
|
||||
var_scopes.emplace_back(s->FindVar(kLocalExecScopeName)->Get<Scope *>());
|
||||
}
|
||||
|
||||
size_t place_num = places_.size();
|
||||
PADDLE_ENFORCE_EQ(in_var_handles.size() * place_num, out_var_handles.size());
|
||||
|
||||
for (size_t i = 0; i < in_var_handles.size(); ++i) {
|
||||
BroadcastOneVar(
|
||||
*in_var_handles[i],
|
||||
std::vector<VarHandle *>(out_var_handles.begin() + i * place_num,
|
||||
out_var_handles.begin() + (i + 1) * place_num),
|
||||
var_scopes);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FusedBroadcastOpHandle::Name() const { return "fused_broadcast"; }
|
||||
|
||||
} // namespace details
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "paddle/fluid/framework/details/broadcast_op_handle.h"
|
||||
#include "paddle/fluid/framework/details/multi_devices_helper.h"
|
||||
#include "paddle/fluid/framework/lod_tensor.h"
|
||||
#include "paddle/fluid/framework/scope.h"
|
||||
#include "paddle/fluid/framework/selected_rows.h"
|
||||
#include "paddle/fluid/platform/device_context.h"
|
||||
|
||||
#ifdef PADDLE_WITH_CUDA
|
||||
#include "paddle/fluid/platform/nccl_helper.h"
|
||||
#endif
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
namespace details {
|
||||
|
||||
struct FusedBroadcastOpHandle : public BroadcastOpHandle {
|
||||
public:
|
||||
#ifdef PADDLE_WITH_CUDA
|
||||
FusedBroadcastOpHandle(ir::Node *node,
|
||||
const std::vector<Scope *> local_scopes,
|
||||
const std::vector<platform::Place> &places,
|
||||
const platform::NCCLContextMap *nccl_ctx)
|
||||
: BroadcastOpHandle(node, local_scopes, places, nccl_ctx) {}
|
||||
#else
|
||||
FusedBroadcastOpHandle(ir::Node* node, const std::vector<Scope*> local_scopes,
|
||||
const std::vector<platform::Place>& places)
|
||||
: BroadcastOpHandle(node, local_scopes, places) {}
|
||||
#endif
|
||||
std::string Name() const override;
|
||||
|
||||
protected:
|
||||
void RunImpl() override;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "paddle/fluid/framework/ir/fuse_pass_base.h"
|
||||
#include "paddle/fluid/framework/ir/graph.h"
|
||||
#include "paddle/fluid/framework/ir/pass.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
namespace ir {
|
||||
|
||||
// BatchMergePass is used to copy forward and backward ops for several
|
||||
// times to run several batches to simulate large batch size training
|
||||
// as if we have more than 1 GPUs.
|
||||
// User can define how many batches to run, gradients will be merged
|
||||
// through those repeats, and then do optimization using merged gradients.
|
||||
// This pass is extremely useful when doing large batch-size distributed
|
||||
// sync training, we can simulate even large batch size as if we have more
|
||||
// GPUs.
|
||||
|
||||
class BatchMergePass : public Pass {
|
||||
public:
|
||||
virtual ~BatchMergePass() {}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Graph> ApplyImpl(std::unique_ptr<Graph> graph) const override;
|
||||
};
|
||||
|
||||
} // namespace ir
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue