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

Remove boost::static_visitor (#44024)

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