未验证 提交 01fedf4f 编写于 作者: R Ruibiao Chen 提交者: GitHub

Remove boost::static_visitor (#44024)

上级 cd00d9b4
...@@ -69,7 +69,8 @@ static DLDataType GetDLDataTypeFromTypeIndex(proto::VarType::Type type) { ...@@ -69,7 +69,8 @@ static DLDataType GetDLDataTypeFromTypeIndex(proto::VarType::Type type) {
#undef REG_DL_DATA_TYPE #undef REG_DL_DATA_TYPE
} }
struct DLDeviceVisitor : public boost::static_visitor<::DLDevice> { struct DLDeviceVisitor
: public std::unary_function<const platform::Place &, ::DLDevice> {
inline ::DLDevice operator()(const platform::CPUPlace &place) const { inline ::DLDevice operator()(const platform::CPUPlace &place) const {
::DLDevice device; ::DLDevice device;
device.device_type = kDLCPU; device.device_type = kDLCPU;
......
...@@ -21,7 +21,7 @@ namespace paddle { ...@@ -21,7 +21,7 @@ namespace paddle {
namespace framework { namespace framework {
namespace ir { namespace ir {
class element_visitor : public boost::static_visitor<Attribute> { class element_visitor {
public: public:
explicit element_visitor(int index) : index_(index) {} explicit element_visitor(int index) : index_(index) {}
...@@ -47,7 +47,7 @@ class element_visitor : public boost::static_visitor<Attribute> { ...@@ -47,7 +47,7 @@ class element_visitor : public boost::static_visitor<Attribute> {
int index_; int index_;
}; };
class operation_visitor : public boost::static_visitor<Attribute> { class operation_visitor {
public: public:
explicit operation_visitor(const proto::PassDesc::OperationType& type) explicit operation_visitor(const proto::PassDesc::OperationType& type)
: type_(type) {} : type_(type) {}
......
...@@ -764,7 +764,7 @@ void OpDesc::RenameInput(const std::string &old_name, ...@@ -764,7 +764,7 @@ void OpDesc::RenameInput(const std::string &old_name,
need_update_ = true; need_update_ = true;
} }
struct SetAttrDescVisitor : public boost::static_visitor<void> { struct SetAttrDescVisitor {
explicit SetAttrDescVisitor(proto::OpDesc::Attr *attr) : attr_(attr) {} explicit SetAttrDescVisitor(proto::OpDesc::Attr *attr) : attr_(attr) {}
mutable proto::OpDesc::Attr *attr_; mutable proto::OpDesc::Attr *attr_;
void operator()(int v) const { attr_->set_i(v); } void operator()(int v) const { attr_->set_i(v); }
......
...@@ -689,7 +689,7 @@ inline void AnyImpl(Predicate predicate, ...@@ -689,7 +689,7 @@ inline void AnyImpl(Predicate predicate,
} }
template <typename Predicate> template <typename Predicate>
class AnyVisitor : public boost::static_visitor<bool> { class AnyVisitor : public std::unary_function<const Place&, bool> {
private: private:
const framework::Tensor& tensor_; const framework::Tensor& tensor_;
Predicate predicate_; Predicate predicate_;
...@@ -774,7 +774,7 @@ class AnyVisitor : public boost::static_visitor<bool> { ...@@ -774,7 +774,7 @@ class AnyVisitor : public boost::static_visitor<bool> {
}; };
template <typename Predicate> template <typename Predicate>
class AnyOutVisitor : public boost::static_visitor<> { class AnyOutVisitor : public std::unary_function<const Place&, void> {
private: private:
const framework::Tensor& tensor_; const framework::Tensor& tensor_;
mutable framework::Tensor* out_; mutable framework::Tensor* out_;
...@@ -843,7 +843,7 @@ inline void AllImpl(Predicate predicate, ...@@ -843,7 +843,7 @@ inline void AllImpl(Predicate predicate,
} }
template <typename Predicate> template <typename Predicate>
class AllOutVisitor : public boost::static_visitor<> { class AllOutVisitor : public std::unary_function<const Place&, void> {
private: private:
const framework::Tensor& tensor_; const framework::Tensor& tensor_;
mutable framework::Tensor* out_; mutable framework::Tensor* out_;
...@@ -942,7 +942,7 @@ static inline void __global__ BothFalse(const T* cmp, T* out, int element_num) { ...@@ -942,7 +942,7 @@ static inline void __global__ BothFalse(const T* cmp, T* out, int element_num) {
} }
#endif #endif
struct BothFalseVisitor : public boost::static_visitor<> { struct BothFalseVisitor : public std::unary_function<const Place&, void> {
const framework::Tensor& in_; const framework::Tensor& in_;
mutable framework::Tensor* out_; mutable framework::Tensor* out_;
BothFalseVisitor(const framework::Tensor& in, framework::Tensor* out) BothFalseVisitor(const framework::Tensor& in, framework::Tensor* out)
......
...@@ -79,7 +79,8 @@ static void MoveOrCopyVar(framework::Variable* dst, ...@@ -79,7 +79,8 @@ static void MoveOrCopyVar(framework::Variable* dst,
} }
template <typename T> template <typename T>
class TensorAddFunctor : public boost::static_visitor<> { class TensorAddFunctor
: public std::unary_function<const platform::Place&, void> {
public: public:
TensorAddFunctor(int64_t numel, const T* x, T* y) TensorAddFunctor(int64_t numel, const T* x, T* y)
: numel_(numel), x_(x), y_(y) {} : numel_(numel), x_(x), y_(y) {}
......
...@@ -59,7 +59,7 @@ uint64_t Release(const Place &place); ...@@ -59,7 +59,7 @@ uint64_t Release(const Place &place);
template <typename Place> template <typename Place>
size_t Used(const Place &place); size_t Used(const Place &place);
struct Usage : public boost::static_visitor<size_t> { struct Usage {
size_t operator()(const platform::CPUPlace &cpu) const; size_t operator()(const platform::CPUPlace &cpu) const;
size_t operator()(const platform::CUDAPlace &gpu) const; size_t operator()(const platform::CUDAPlace &gpu) const;
size_t operator()(const platform::CUDAPinnedPlace &cuda_pinned) const; size_t operator()(const platform::CUDAPinnedPlace &cuda_pinned) const;
...@@ -894,7 +894,7 @@ size_t Used<platform::CustomPlace>(const platform::CustomPlace &place) { ...@@ -894,7 +894,7 @@ size_t Used<platform::CustomPlace>(const platform::CustomPlace &place) {
#endif #endif
} }
struct AllocVisitor : public boost::static_visitor<void *> { struct AllocVisitor : std::unary_function<const Place, void *> {
inline explicit AllocVisitor(size_t size) : size_(size) {} inline explicit AllocVisitor(size_t size) : size_(size) {}
template <typename Place> template <typename Place>
...@@ -906,7 +906,7 @@ struct AllocVisitor : public boost::static_visitor<void *> { ...@@ -906,7 +906,7 @@ struct AllocVisitor : public boost::static_visitor<void *> {
size_t size_; size_t size_;
}; };
struct FreeVisitor : public boost::static_visitor<void> { struct FreeVisitor : public std::unary_function<const Place, void> {
inline explicit FreeVisitor(void *ptr, size_t size) inline explicit FreeVisitor(void *ptr, size_t size)
: ptr_(ptr), size_(size) {} : ptr_(ptr), size_(size) {}
...@@ -920,7 +920,7 @@ struct FreeVisitor : public boost::static_visitor<void> { ...@@ -920,7 +920,7 @@ struct FreeVisitor : public boost::static_visitor<void> {
size_t size_; size_t size_;
}; };
struct ReleaseVisitor : public boost::static_visitor<uint64_t> { struct ReleaseVisitor : std::unary_function<const Place, uint64_t> {
template <typename Place> template <typename Place>
inline uint64_t operator()(const Place &place) const { inline uint64_t operator()(const Place &place) const {
return Release<Place>(place); return Release<Place>(place);
......
...@@ -43,7 +43,7 @@ struct ArrayToLoDFunctorImpl { ...@@ -43,7 +43,7 @@ struct ArrayToLoDFunctorImpl {
void apply(); void apply();
}; };
struct ArrayToLoDFunctor : public boost::static_visitor<void> { struct ArrayToLoDFunctor : public std::unary_function<platform::Place, void> {
std::vector<framework::Tensor> in; std::vector<framework::Tensor> in;
mutable framework::Tensor *out; mutable framework::Tensor *out;
......
...@@ -29,7 +29,7 @@ namespace operators { ...@@ -29,7 +29,7 @@ namespace operators {
// FeedVariableVisitor is to feed the variable data // FeedVariableVisitor is to feed the variable data
// according to data type (LoDTensor or Strings). // according to data type (LoDTensor or Strings).
class FeedVariableVisitor : public boost::static_visitor<void> { class FeedVariableVisitor {
public: public:
explicit FeedVariableVisitor(framework::Variable *out_var, explicit FeedVariableVisitor(framework::Variable *out_var,
const platform::Place &place) const platform::Place &place)
......
...@@ -17,24 +17,21 @@ ...@@ -17,24 +17,21 @@
namespace paddle { namespace paddle {
namespace operators { namespace operators {
struct InputsVisitor struct InputsVisitor {
: public boost::static_visitor<const framework::VariableNameMap *> {
template <typename OpType> template <typename OpType>
const framework::VariableNameMap *operator()(const OpType *op) const { const framework::VariableNameMap *operator()(const OpType *op) const {
return &(op->Inputs()); return &(op->Inputs());
} }
}; };
struct OutputsVisitor struct OutputsVisitor {
: public boost::static_visitor<const framework::VariableNameMap *> {
template <typename OpType> template <typename OpType>
const framework::VariableNameMap *operator()(const OpType *op) const { const framework::VariableNameMap *operator()(const OpType *op) const {
return &(op->Outputs()); return &(op->Outputs());
} }
}; };
struct AttributeMapVisitor struct AttributeMapVisitor {
: public boost::static_visitor<const framework::AttributeMap *> {
const framework::AttributeMap *operator()(const framework::OpDesc *op) const { const framework::AttributeMap *operator()(const framework::OpDesc *op) const {
return &(op->GetAttrMap()); return &(op->GetAttrMap());
} }
...@@ -45,7 +42,7 @@ struct AttributeMapVisitor ...@@ -45,7 +42,7 @@ struct AttributeMapVisitor
} }
}; };
struct RawPointerVisitor : public boost::static_visitor<const void *> { struct RawPointerVisitor {
template <typename OpType> template <typename OpType>
const void *operator()(const OpType *op) const { const void *operator()(const OpType *op) const {
return op; return op;
......
...@@ -44,7 +44,8 @@ struct LoDTensorToArrayFunctorImpl { ...@@ -44,7 +44,8 @@ struct LoDTensorToArrayFunctorImpl {
void apply(); void apply();
}; };
struct LoDTensorToArrayFunctor : public boost::static_visitor<void> { struct LoDTensorToArrayFunctor
: public std::unary_function<platform::Place, void> {
std::vector<const framework::Tensor *> ref_inputs_; std::vector<const framework::Tensor *> ref_inputs_;
mutable std::vector<framework::Tensor *> outputs_; mutable std::vector<framework::Tensor *> outputs_;
const framework::Tensor &input_; const framework::Tensor &input_;
......
...@@ -19,7 +19,7 @@ namespace operators { ...@@ -19,7 +19,7 @@ namespace operators {
namespace math { namespace math {
template <typename T> template <typename T>
struct MatrixBitCodeFunctorAdd : public boost::static_visitor<void> { struct MatrixBitCodeFunctorAdd {
const framework::Tensor &vec_; const framework::Tensor &vec_;
framework::Tensor *tmat_; framework::Tensor *tmat_;
...@@ -51,7 +51,7 @@ void MatrixBitCodeFunctor<T>::Add(const framework::Tensor &vec, ...@@ -51,7 +51,7 @@ void MatrixBitCodeFunctor<T>::Add(const framework::Tensor &vec,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorAddGrad : public boost::static_visitor<void> { struct MatrixBitCodeFunctorAddGrad {
const framework::Tensor &tmat_; const framework::Tensor &tmat_;
framework::Tensor *vec_; framework::Tensor *vec_;
MatrixBitCodeFunctorAddGrad(const framework::Tensor &tmat, MatrixBitCodeFunctorAddGrad(const framework::Tensor &tmat,
...@@ -83,7 +83,7 @@ void MatrixBitCodeFunctor<T>::AddGrad(const framework::Tensor &tmat, ...@@ -83,7 +83,7 @@ void MatrixBitCodeFunctor<T>::AddGrad(const framework::Tensor &tmat,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorSum : public boost::static_visitor<void> { struct MatrixBitCodeFunctorSum {
const framework::Tensor &tmat_; const framework::Tensor &tmat_;
framework::Tensor *sum_; framework::Tensor *sum_;
T scale_sum_; T scale_sum_;
...@@ -125,7 +125,7 @@ void MatrixBitCodeFunctor<T>::Sum(const framework::Tensor &tmat, ...@@ -125,7 +125,7 @@ void MatrixBitCodeFunctor<T>::Sum(const framework::Tensor &tmat,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorMul : public boost::static_visitor<void> { struct MatrixBitCodeFunctorMul {
framework::Tensor *tmat_; framework::Tensor *tmat_;
const framework::Tensor &weight_; const framework::Tensor &weight_;
const framework::Tensor &input_; const framework::Tensor &input_;
...@@ -174,7 +174,7 @@ class ReservedVector : public std::vector<T> { ...@@ -174,7 +174,7 @@ class ReservedVector : public std::vector<T> {
}; };
template <typename T> template <typename T>
struct MatrixBitCodeFunctorMulGradWeight : public boost::static_visitor<void> { struct MatrixBitCodeFunctorMulGradWeight {
const framework::Tensor &tmat_; const framework::Tensor &tmat_;
framework::Tensor *weight_; framework::Tensor *weight_;
const framework::Tensor &input_; const framework::Tensor &input_;
...@@ -224,8 +224,7 @@ void MatrixBitCodeFunctor<T>::MulGradWeight(const framework::Tensor &tmat, ...@@ -224,8 +224,7 @@ void MatrixBitCodeFunctor<T>::MulGradWeight(const framework::Tensor &tmat,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorMulGradWeightSR struct MatrixBitCodeFunctorMulGradWeightSR {
: public boost::static_visitor<void> {
const framework::Tensor &tmat_; const framework::Tensor &tmat_;
phi::SelectedRows *weight_; phi::SelectedRows *weight_;
const framework::Tensor &input_; const framework::Tensor &input_;
...@@ -280,7 +279,7 @@ void MatrixBitCodeFunctor<T>::MulGradWeight(const framework::Tensor &tmat, ...@@ -280,7 +279,7 @@ void MatrixBitCodeFunctor<T>::MulGradWeight(const framework::Tensor &tmat,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorMulGradError : public boost::static_visitor<void> { struct MatrixBitCodeFunctorMulGradError {
const framework::Tensor &tmat_; const framework::Tensor &tmat_;
const framework::Tensor &weight_; const framework::Tensor &weight_;
framework::Tensor *input_; framework::Tensor *input_;
...@@ -324,7 +323,7 @@ void MatrixBitCodeFunctor<T>::MulGradError(const framework::Tensor &tmat, ...@@ -324,7 +323,7 @@ void MatrixBitCodeFunctor<T>::MulGradError(const framework::Tensor &tmat,
} }
template <typename T> template <typename T>
struct MatrixBitCodeFunctorSub : public boost::static_visitor<void> { struct MatrixBitCodeFunctorSub {
framework::Tensor *tmat_; framework::Tensor *tmat_;
explicit MatrixBitCodeFunctorSub(framework::Tensor *tmat) : tmat_(tmat) {} explicit MatrixBitCodeFunctorSub(framework::Tensor *tmat) : tmat_(tmat) {}
......
...@@ -32,7 +32,7 @@ namespace ipu { ...@@ -32,7 +32,7 @@ namespace ipu {
namespace { namespace {
struct CustomOpAttrVisitor : public boost::static_visitor<void> { struct CustomOpAttrVisitor {
CustomOpAttrVisitor(std::map<std::string, popart::any>* attr, CustomOpAttrVisitor(std::map<std::string, popart::any>* attr,
const std::string& attr_name) const std::string& attr_name)
: attrs_(attr), attr_name_(attr_name) {} : attrs_(attr), attr_name_(attr_name) {}
...@@ -82,7 +82,7 @@ struct CustomOpAttrVisitor : public boost::static_visitor<void> { ...@@ -82,7 +82,7 @@ struct CustomOpAttrVisitor : public boost::static_visitor<void> {
} }
}; };
struct ConstantOpAttrVisitor : public boost::static_visitor<void> { struct ConstantOpAttrVisitor {
ConstantOpAttrVisitor(framework::LoDTensor* tensor, VarType::Type dtype) ConstantOpAttrVisitor(framework::LoDTensor* tensor, VarType::Type dtype)
: tensor_(tensor), dtype_(dtype) {} : tensor_(tensor), dtype_(dtype) {}
......
...@@ -40,7 +40,6 @@ limitations under the License. */ ...@@ -40,7 +40,6 @@ limitations under the License. */
#include <boost/mpl/comparison.hpp> #include <boost/mpl/comparison.hpp>
#include <boost/mpl/less_equal.hpp> #include <boost/mpl/less_equal.hpp>
#include <boost/variant.hpp>
#include "paddle/utils/any.h" #include "paddle/utils/any.h"
#include "paddle/utils/optional.h" #include "paddle/utils/optional.h"
......
...@@ -217,7 +217,7 @@ void BindGlobalValueGetterSetter(pybind11::module *module) { ...@@ -217,7 +217,7 @@ void BindGlobalValueGetterSetter(pybind11::module *module) {
GlobalVarGetterSetterRegistry::CreateSetter(&var)); \ GlobalVarGetterSetterRegistry::CreateSetter(&var)); \
} while (0) } while (0)
struct RegisterGetterSetterVisitor : public boost::static_visitor<void> { struct RegisterGetterSetterVisitor {
RegisterGetterSetterVisitor(const std::string &name, RegisterGetterSetterVisitor(const std::string &name,
bool is_writable, bool is_writable,
void *value_ptr) void *value_ptr)
......
...@@ -18,14 +18,12 @@ limitations under the License. */ ...@@ -18,14 +18,12 @@ limitations under the License. */
#include <vector> #include <vector>
#include "glog/logging.h" #include "glog/logging.h"
#include "paddle/fluid/platform/variant.h"
#include "paddle/utils/variant.h" #include "paddle/utils/variant.h"
#include "pybind11/numpy.h" #include "pybind11/numpy.h"
#include "pybind11/pybind11.h" #include "pybind11/pybind11.h"
#include "pybind11/stl.h" #include "pybind11/stl.h"
// Cast paddle::variant for PyBind. // Cast paddle::variant for PyBind.
// Copy from // Copy from
// https://github.com/pybind/pybind11/issues/576#issuecomment-269563199 // https://github.com/pybind/pybind11/issues/576#issuecomment-269563199
namespace pybind11 { namespace pybind11 {
namespace detail { namespace detail {
...@@ -78,10 +76,7 @@ struct paddle_variant_caster<V<Ts...>> { ...@@ -78,10 +76,7 @@ struct paddle_variant_caster<V<Ts...>> {
using Type = V<Ts...>; using Type = V<Ts...>;
template <typename T> template <typename T>
typename std::enable_if< bool try_load(handle src, bool convert) {
!std::is_same<T, boost::detail::variant::void_>::value,
bool>::type
try_load(handle src, bool convert) {
auto caster = make_caster<T>(); auto caster = make_caster<T>();
if (!load_success_ && caster.load(src, convert)) { if (!load_success_ && caster.load(src, convert)) {
load_success_ = true; load_success_ = true;
...@@ -112,13 +107,6 @@ struct paddle_variant_caster<V<Ts...>> { ...@@ -112,13 +107,6 @@ struct paddle_variant_caster<V<Ts...>> {
return false; return false;
} }
template <typename T>
typename std::enable_if<std::is_same<T, boost::detail::variant::void_>::value,
bool>::type
try_load(handle src, bool convert) {
return false;
}
bool load(handle src, bool convert) { bool load(handle src, bool convert) {
auto unused = {false, try_load<Ts>(src, convert)...}; auto unused = {false, try_load<Ts>(src, convert)...};
(void)(unused); (void)(unused);
...@@ -128,11 +116,6 @@ struct paddle_variant_caster<V<Ts...>> { ...@@ -128,11 +116,6 @@ struct paddle_variant_caster<V<Ts...>> {
static handle cast(Type const& src, static handle cast(Type const& src,
return_value_policy policy, return_value_policy policy,
handle parent) { handle parent) {
/*
auto paddle_variant_caster_visitor = [&](Type const& src)->handle {
return make_caster<Type>::cast(src, policy, parent);
}
*/
paddle_variant_caster_visitor visitor(policy, parent); paddle_variant_caster_visitor visitor(policy, parent);
return paddle::visit(visitor, src); return paddle::visit(visitor, src);
} }
......
...@@ -214,7 +214,8 @@ void set_constant_with_place<paddle::platform::CUDAPinnedPlace>( ...@@ -214,7 +214,8 @@ void set_constant_with_place<paddle::platform::CUDAPinnedPlace>(
phi::VisitDataType(tensor->dtype(), TensorSetConstantCPU(tensor, value)); phi::VisitDataType(tensor->dtype(), TensorSetConstantCPU(tensor, value));
} }
struct TensorSetConstantWithPlace : public boost::static_visitor<void> { struct TensorSetConstantWithPlace
: public std::unary_function<paddle::platform::Place, void> {
TensorSetConstantWithPlace(const paddle::platform::DeviceContext& context, TensorSetConstantWithPlace(const paddle::platform::DeviceContext& context,
paddle::framework::Tensor* tensor, paddle::framework::Tensor* tensor,
float value) float value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册