Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/collective/HCCLTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <string>

#include "boost/variant.hpp"
#include "paddle/fluid/distributed/collective/Types.h"
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/variable.h"
Expand All @@ -27,6 +26,7 @@
#include "paddle/fluid/platform/device/npu/npu_info.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/utils/variant.h"

namespace paddle {
namespace distributed {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/collective/NCCLTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <string>

#include "boost/variant.hpp"
#include "paddle/fluid/distributed/collective/Types.h"
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/variable.h"
Expand All @@ -43,6 +42,7 @@
#endif

#include "paddle/fluid/platform/enforce.h"
#include "paddle/utils/variant.h"

namespace paddle {
namespace distributed {
Expand Down
50 changes: 26 additions & 24 deletions paddle/fluid/eager/auto_code_generator/eager_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,45 +336,47 @@ static std::string AttrTypeToString(const proto::AttrType& type) {
}
default: {
PADDLE_THROW(platform::errors::Fatal(
"AttrType of type boost::variant only supports specific data types."
"AttrType of type paddle::variant only supports specific data types."
"However, detected unrecognized AttrType: %d",
type));
}
}
return ret;
}

template <typename T>
static std::string GetAttrValue(const framework::Attribute& attr,
bool is_vector) {
template <typename T, bool IsVector>
static typename std::enable_if<IsVector, std::string>::type GetAttrValue(
const framework::Attribute& attr) {
std::string val = "";
if (is_vector) {
val += "{";
for (auto x : BOOST_GET_CONST(std::vector<T>, attr)) {
val += std::to_string(x) + ",";
}
if (val.size() > 1) val.pop_back();
val += "}";
} else {
val = std::to_string(BOOST_GET_CONST(T, attr));
val += "{";
for (auto x : BOOST_GET_CONST(std::vector<T>, attr)) {
val += std::to_string(x) + ",";
}
if (val.size() > 1) val.pop_back();
val += "}";
return val;
}

template <typename T, bool IsVector>
static typename std::enable_if<!IsVector, std::string>::type GetAttrValue(
const framework::Attribute& attr) {
return std::to_string(BOOST_GET_CONST(T, attr));
}

static std::pair<std::string, std::string> GetAttrType(
const framework::Attribute& attr, bool is_arg) {
std::string ret = "";
std::string val = "";
size_t variant_pos = attr.which();
size_t variant_pos = attr.index();
switch (variant_pos) {
case (1): {
ret = "int";
val = GetAttrValue<int>(attr, false);
val = GetAttrValue<int, false>(attr);
break;
}
case (2): {
ret = "float";
val = GetAttrValue<float>(attr, false);
val = GetAttrValue<float, false>(attr);
break;
}
case (3): {
Expand All @@ -386,13 +388,13 @@ static std::pair<std::string, std::string> GetAttrType(
case (4): {
ret = "std::vector<int>";
if (is_arg) ret += "&";
val = GetAttrValue<int>(attr, true);
val = GetAttrValue<int, true>(attr);
break;
}
case (5): {
ret = "std::vector<float>";
if (is_arg) ret += "&";
val = GetAttrValue<float>(attr, true);
val = GetAttrValue<float, true>(attr);
break;
}
case (6): {
Expand All @@ -408,13 +410,13 @@ static std::pair<std::string, std::string> GetAttrType(
}
case (7): {
ret = "bool";
val = GetAttrValue<bool>(attr, false);
val = GetAttrValue<bool, false>(attr);
break;
}
case (8): {
ret = "std::vector<bool>";
if (is_arg) ret += "&";
val = GetAttrValue<bool>(attr, true);
val = GetAttrValue<bool, true>(attr);
break;
}
case (9): {
Expand All @@ -423,7 +425,7 @@ static std::pair<std::string, std::string> GetAttrType(
}
case (10): {
ret = "int64_t";
val = GetAttrValue<int64_t>(attr, false);
val = GetAttrValue<int64_t, false>(attr);
break;
}
case (11): {
Expand All @@ -434,18 +436,18 @@ static std::pair<std::string, std::string> GetAttrType(
case (12): {
ret = "std::vector<int64_t>";
if (is_arg) ret += "&";
val = GetAttrValue<int64_t>(attr, true);
val = GetAttrValue<int64_t, true>(attr);
break;
}
case (13): {
ret = "std::vector<double>";
if (is_arg) ret += "&";
val = GetAttrValue<double>(attr, true);
val = GetAttrValue<double, true>(attr);
break;
}
default: {
PADDLE_THROW(platform::errors::Fatal(
"AttrType of type boost::variant only supports specific data types."
"AttrType of type paddle::variant only supports specific data types."
"However, detected unrecognized AttrType: %d",
variant_pos));
}
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/framework/attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/framework/attribute.h"
#include "boost/blank.hpp"

namespace paddle {
namespace framework {
Expand Down
30 changes: 15 additions & 15 deletions paddle/fluid/framework/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ limitations under the License. */
#include <unordered_set>
#include <vector>

#include "boost/variant/get.hpp"
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/type_defs.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/errors.h"
#include "paddle/utils/any.h"
#include "paddle/utils/variant.h"

namespace paddle {
namespace framework {
Expand All @@ -45,8 +45,8 @@ struct ExtractAttribute {
T* operator()(Attribute& attr) const {
T* attr_value = nullptr;
try {
attr_value = &boost::get<T>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<T>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type %s, its type is %s.",
attr_name_,
Expand Down Expand Up @@ -80,8 +80,8 @@ struct ExtractAttribute<bool> {
}
bool* attr_value = nullptr;
try {
attr_value = &boost::get<bool>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<bool>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type bool, its type is %s.",
attr_name_,
Expand All @@ -108,8 +108,8 @@ struct ExtractAttribute<int64_t> {
}
int64_t* attr_value = nullptr;
try {
attr_value = &boost::get<int64_t>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<int64_t>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type int64_t, its type is %s.",
attr_name_,
Expand Down Expand Up @@ -138,8 +138,8 @@ struct ExtractAttribute<std::vector<int64_t>> {
}
std::vector<int64_t>* attr_value = nullptr;
try {
attr_value = &boost::get<std::vector<int64_t>>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<std::vector<int64_t>>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type std::vector<int64_t>, its type is "
"%s.",
Expand Down Expand Up @@ -167,8 +167,8 @@ struct ExtractAttribute<float> {
}
float* attr_value = nullptr;
try {
attr_value = &boost::get<float>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<float>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type float, its type is %s.",
attr_name_,
Expand Down Expand Up @@ -197,8 +197,8 @@ struct ExtractAttribute<std::vector<double>> {
}
std::vector<double>* attr_value = nullptr;
try {
attr_value = &boost::get<std::vector<double>>(attr);
} catch (boost::bad_get& bad_get) {
attr_value = &paddle::get<std::vector<double>>(attr);
} catch (paddle::bad_variant_access const& bad_get) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Cannot get attribute (%s) by type std::vector<double>, its type is "
"%s.",
Expand All @@ -214,11 +214,11 @@ struct ExtractAttribute<std::vector<double>> {
template <typename T>
inline proto::AttrType AttrTypeID() {
Attribute tmp = T();
return static_cast<proto::AttrType>(tmp.which() - 1);
return static_cast<proto::AttrType>(tmp.index() - 1);
}

inline proto::AttrType AttrTypeID(const Attribute& attr) {
return static_cast<proto::AttrType>(attr.which() - 1);
return static_cast<proto::AttrType>(attr.index() - 1);
}

class AttrReader {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/block_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void BlockDesc::MoveFrom(BlockDesc *block) {
for (const auto &pair : src_op->GetAttrMap()) {
const auto &attr_name = pair.first;
const auto &attr_value = pair.second;
auto attr_type = static_cast<proto::AttrType>(attr_value.which() - 1);
auto attr_type = static_cast<proto::AttrType>(attr_value.index() - 1);
if (attr_type == proto::AttrType::BLOCK) {
auto block_id = BOOST_GET_CONST(BlockDesc *, attr_value)->ID();
dst_op->SetBlockAttr(attr_name, prog_->MutableBlock(block_id));
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/details/async_ssa_graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ FetchResultType AsyncSSAGraphExecutor::Run(
HandleException();

FetchList ret;
auto &val = BOOST_GET(FetchList, fetch_data);
auto &val = boost::get<FetchList>(fetch_data);
for (size_t fetch_idx = 0; fetch_idx < fetch_tensors.size(); ++fetch_idx) {
if (data_is_lod_tensor(val.at(fetch_idx))) {
std::vector<const LoDTensor *> lodtensor_ptrs;
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/details/fetch_async_op_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void FetchAsyncOpHandle::RunImpl() {
}

if (return_merged_) {
auto &val = BOOST_GET(FetchList, *data_);
auto &val = boost::get<FetchList>(*data_);
if (src_vars[0]->IsType<LoDTensor>()) {
// to lodtensor type
std::vector<const LoDTensor *> src_lodtensors;
Expand Down Expand Up @@ -263,7 +263,7 @@ void FetchAsyncOpHandle::RunImpl() {
val.at(offset_) = std::move(dst_lodtensor_array);
}
} else {
auto &val = BOOST_GET(FetchUnmergedList, *data_);
auto &val = boost::get<FetchUnmergedList>(*data_);
auto &dst_tensors = val.at(offset_);
dst_tensors.reserve(src_vars.size());

Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/framework/details/fetch_op_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
for (auto &t : tensors_) {
tensors_ptr.emplace_back(&BOOST_GET_CONST(LoDTensor, t));
}
auto &val = BOOST_GET(FetchList, *data_);
auto &val = boost::get<FetchList>(*data_);
LoDTensor var;
MergeLoDTensor(&var, tensors_ptr, platform::CPUPlace());
val.at(offset_) = std::move(var);
Expand All @@ -106,11 +106,11 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
tmp_array.emplace_back();
MergeLoDTensor(&(tmp_array.back()), tensors_ptr, platform::CPUPlace());
}
auto &val = BOOST_GET(FetchList, *data_);
auto &val = boost::get<FetchList>(*data_);
val.at(offset_) = std::move(tmp_array);
}
} else {
auto &val = BOOST_GET(FetchUnmergedList, *data_);
auto &val = boost::get<FetchUnmergedList>(*data_);
val.at(offset_) = std::move(tensors_);
}
}
Expand Down
5 changes: 2 additions & 3 deletions paddle/fluid/framework/details/parallel_ssa_graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
if (!is_valid[scope_idx]) {
continue;
}
const auto &fetch_list =
BOOST_GET_CONST(FetchList, fetch_data[scope_idx]);
const auto &fetch_list = boost::get<FetchList>(fetch_data[scope_idx]);
if (data_is_lod_tensor(fetch_list[fetch_idx])) {
lodtensor_ptrs.push_back(
&(BOOST_GET_CONST(LoDTensor, fetch_list[fetch_idx])));
Expand Down Expand Up @@ -318,7 +317,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
continue;
}
const auto &fetch_list =
BOOST_GET_CONST(FetchUnmergedList, fetch_data[scope_idx]);
boost::get<FetchUnmergedList>(fetch_data[scope_idx]);
PADDLE_ENFORCE_EQ(
fetch_list[fetch_idx].size(),
1,
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/feed_fetch_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ limitations under the License. */

namespace paddle {
namespace framework {
using FeedType = boost::variant<LoDTensor, Strings>;
using FeedType = paddle::variant<LoDTensor, Strings>;
using FeedList = std::vector<FeedType>;

using FetchType = boost::variant<LoDTensor, LoDTensorArray>;
using FetchType = paddle::variant<LoDTensor, LoDTensorArray, framework::Vocab>;
using FetchList = std::vector<FetchType>;

using FetchUnmergedList = std::vector<std::vector<FetchType>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void ConvElementwiseAddFusePass::ApplyImpl(ir::Graph* graph) const {
elementwise_add_op_desc->GetNullableAttr("out_threshold");
// set the out_threshold of the elementwise add op to be the out_threshold
// of the conv2d_fusion
if (out_threshold_attr.which()) {
if (out_threshold_attr.index()) {
new_op_desc.SetAttr("out_threshold", out_threshold_attr);
}
new_op_desc.Flush();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/ir/fc_fuse_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int FCFusePass::ApplyFCPattern(Graph* graph, bool with_relu) const {
// out_thrshold of fc
auto out_threshold_attr =
elementwise_add_op_desc->GetNullableAttr("out_threshold");
if (out_threshold_attr.which()) {
if (out_threshold_attr.index()) {
VLOG(4) << "setting out_threshold: "
<< BOOST_GET_CONST(float, out_threshold_attr);
desc.SetAttr("out_threshold", out_threshold_attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static std::string RefineTemplateWithAttr(const std::string& op_type,
}
Attribute attr = it->second;
proto::AttrType attr_type =
static_cast<proto::AttrType>(it->second.which() - 1);
static_cast<proto::AttrType>(it->second.index() - 1);
if (attr_type == proto::AttrType::BOOLEAN) {
bool result = BOOST_GET(bool, attr);
if (result) {
Expand Down
Loading