Skip to content

Commit

Permalink
[CompileOpt] Refine enforce code and remove boost/variant include (Pa…
Browse files Browse the repository at this point in the history
…ddlePaddle#41093)

* refine enforce code

* refine enforce code

* fix compile failed

* fix infrt failed
  • Loading branch information
chenwhql authored and Yaocheng committed May 19, 2022
1 parent ef5b392 commit 0b430fa
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 198 deletions.
8 changes: 7 additions & 1 deletion paddle/fluid/framework/type_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ limitations under the License. */
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/variant.h"
#include "paddle/phi/core/compat/type_defs.h"
#include "paddle/utils/small_vector.h"

namespace paddle {
Expand All @@ -39,6 +39,12 @@ class InferNoNeedBufferVarsFN;
using VariableNameMap = std::map<std::string, std::vector<std::string>>;
using VariableValueMap = std::map<std::string, std::vector<Variable*>>;

using Attribute = boost::variant<
boost::blank, int, float, std::string, std::vector<int>, std::vector<float>,
std::vector<std::string>, bool, std::vector<bool>, BlockDesc*, int64_t,
std::vector<BlockDesc*>, std::vector<int64_t>, std::vector<double>>;
using AttributeMap = std::unordered_map<std::string, Attribute>;

#ifdef PADDLE_WITH_ASCEND_CL
using NPUAttribute =
boost::variant<boost::blank, int, float, std::string, std::vector<int>,
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/layout_autotune.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <glog/logging.h>
#include <memory>
#include <unordered_set>
#include "paddle/fluid/framework/type_defs.h"
#include "paddle/phi/common/layout.h"
#include "paddle/phi/core/compat/type_defs.h"

namespace paddle {
namespace imperative {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/tests/test_eager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "paddle/fluid/imperative/execution_context.h"
#include "paddle/fluid/imperative/layer.h"
#include "paddle/fluid/imperative/tracer.h"
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/imperative/var_helper.h"
#include "paddle/fluid/memory/memcpy.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/phi/core/compat/type_defs.h"

namespace paddle {
namespace imperative {
Expand Down
56 changes: 55 additions & 1 deletion paddle/fluid/imperative/type_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,58 @@ See the License for the specific language governing permissions and
limitations under the License. */

#pragma once
#include "paddle/phi/core/compat/type_defs.h"

#include <map>
#include <memory>
#include <string>
#include <vector>

namespace egr {
class EagerVariable;
}
namespace paddle {
namespace imperative {

class VariableWrapper;
class SavedVariableWrapperList;
class VarBase;
class OpBase;
class GradOpNode;
class Tracer;

using WeakNameVarBaseMap =
std::map<std::string, std::vector<std::weak_ptr<VarBase>>>;

namespace details {
template <typename T>
struct NameVarMapTrait {};

template <>
struct NameVarMapTrait<VarBase> {
using Type = std::map<std::string, std::vector<std::shared_ptr<VarBase>>>;
};

template <>
struct NameVarMapTrait<VariableWrapper> {
using Type = std::map<std::string, SavedVariableWrapperList>;
};

template <>
struct NameVarMapTrait<egr::EagerVariable> {
using Type =
std::map<std::string, std::vector<std::shared_ptr<egr::EagerVariable>>>;
};

} // namespace details

template <typename T>
using NameVarMap = typename details::NameVarMapTrait<T>::Type;

using NameVarBaseMap = NameVarMap<VarBase>;
using NameVariableWrapperMap = NameVarMap<VariableWrapper>;
using NameTensorMap = NameVarMap<egr::EagerVariable>;

using VariableWrapperList = std::vector<std::shared_ptr<VariableWrapper>>;

} // namespace imperative
} // namespace paddle
4 changes: 2 additions & 2 deletions paddle/fluid/memory/allocation/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace allocation {
// Exception when `Alloc`/`AllocShared` failed
struct BadAlloc : public std::exception {
inline explicit BadAlloc(std::string err_msg, const char* file, int line)
: err_str_(platform::GetTraceBackString(std::move(err_msg), file, line)) {
}
: err_str_(platform::GetCompleteTraceBackString(std::move(err_msg), file,
line)) {}

const char* what() const noexcept override { return err_str_.c_str(); }

Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/pybind/imperative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ limitations under the License. */
#include "paddle/fluid/pybind/tensor_py.h"
#include "paddle/fluid/pybind/uva_utils.h"
#include "paddle/phi/core/compat/arg_map_context.h"
#include "paddle/phi/core/compat/type_defs.h"
#include "paddle/phi/core/type_defs.h"

namespace paddle {
Expand Down
2 changes: 2 additions & 0 deletions paddle/infrt/tensor/phi/tensor_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <unordered_map>

#include "paddle/phi/core/dense_tensor.h"

namespace infrt {
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/backends/device_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "paddle/phi/backends/device_base.h"
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "paddle/phi/core/enforce.h"

DECLARE_double(fraction_of_gpu_memory_to_use);
Expand Down
2 changes: 2 additions & 0 deletions paddle/phi/backends/device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#pragma once
#ifdef PADDLE_WITH_CUSTOM_DEVICE

#include <unordered_map>

#include "paddle/phi/backends/device_base.h"
#include "paddle/phi/backends/device_ext.h"
#include "paddle/phi/backends/event.h"
Expand Down
4 changes: 3 additions & 1 deletion paddle/phi/backends/gpu/gpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/phi/backends/gpu/gpu_context.h"

#include <algorithm>
#include <array>
#include <functional>
#include <future>
#include <memory>
#include <mutex>

#include "paddle/phi/api/ext/exception.h"
#include "glog/logging.h"

#include "paddle/phi/api/ext/exception.h"
#include "paddle/phi/backends/gpu/gpu_decls.h"
#include "paddle/phi/backends/gpu/gpu_info.h"
#include "paddle/phi/backends/gpu/gpu_resources.h"
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(phi_enforce_deps errors flags)
if(WITH_GPU)
set(phi_enforce_deps ${phi_enforce_deps} external_error_proto)
endif()
cc_library(phi_enforce INTERFACE SRCS enforce.cc DEPS ${phi_enforce_deps})
cc_library(phi_enforce SRCS enforce.cc DEPS ${phi_enforce_deps})

cc_library(kernel_factory SRCS kernel_factory.cc DEPS phi_enforce fluid_convert_utils)
cc_library(kernel_context SRCS kernel_context.cc DEPS phi_enforce phi_context)
Expand Down
2 changes: 2 additions & 0 deletions paddle/phi/core/compat/op_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License. */
#include <string>
#include <unordered_set>

#include "glog/logging.h"

#include "paddle/phi/core/compat/arg_map_context.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/infermeta_utils.h"
Expand Down
96 changes: 0 additions & 96 deletions paddle/phi/core/compat/type_defs.h

This file was deleted.

2 changes: 2 additions & 0 deletions paddle/phi/core/custom_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "paddle/phi/core/custom_kernel.h"

#include "glog/logging.h"

namespace phi {

void CustomKernelMap::RegisterCustomKernel(const std::string& name,
Expand Down
Loading

0 comments on commit 0b430fa

Please sign in to comment.