Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmp:fix bugs for vis-formula; test=develop #10528

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lite/core/optimizer/mir/xpu_memory_optimize_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void XPUMemoryOptimizePass::CollectLifeCycleByDevice(SSAGraph* graph) {
"scale",
"__xpu__resnet50",
"softmax",
"select_input",
};

auto insert_invalid_op_nodes_for_specific_target =
Expand Down
5 changes: 5 additions & 0 deletions lite/kernels/host/cast_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ void CastCompute::Run() {
const int32_t* x_data_end = x_data_begin + param.X->numel();
bool* out_data = param.Out->mutable_data<bool>();
std::transform(x_data_begin, x_data_end, out_data, TransOp<int32_t, bool>);
} else if (param.in_dtype == 3 && param.out_dtype == 0) { // INT64 -> bool
const int64_t* x_data_begin = param.X->data<int64_t>();
const int64_t* x_data_end = x_data_begin + param.X->numel();
bool* out_data = param.Out->mutable_data<bool>();
std::transform(x_data_begin, x_data_end, out_data, TransOp<int64_t, bool>);
} else if (param.in_dtype == 2 && param.out_dtype == 2) { // INT32 -> INT32
const int32_t* x_data_begin = param.X->data<int32_t>();
const int32_t* x_data_end = x_data_begin + param.X->numel();
Expand Down
1 change: 1 addition & 0 deletions lite/kernels/xpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ add_kernel(gather_nd_compute_xpu XPU extra SRCS gather_nd_compute.cc)
add_kernel(meshgrid_compute_xpu XPU basic SRCS meshgrid_compute.cc)
add_kernel(fetch_compute_xpu XPU basic SRCS fetch_compute.cc)
add_kernel(unbind_compute_xpu XPU basic SRCS unbind_compute.cc)
add_kernel(unbind_compute_xpu XPU basic SRCS unbind_compute.cc)

# extra
add_kernel(lookup_table_compute_xpu XPU extra SRCS lookup_table_compute.cc)
Expand Down
8 changes: 4 additions & 4 deletions lite/kernels/xpu/activation_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ void SigmoidCompute<T, PType>::Run() {
auto& param = this->template Param<param_t>();
auto& ctx = this->ctx_->template As<XPUContext>();

int r = xdnn::fast_sigmoid(ctx.GetRawContext(),
param.X->template data<T>(),
param.Out->template mutable_data<T>(TARGET(kXPU)),
param.X->numel());
int r = xdnn::sigmoid(ctx.GetRawContext(),
param.X->template data<T>(),
param.Out->template mutable_data<T>(TARGET(kXPU)),
param.X->numel());
CHECK_EQ(r, 0);
}

Expand Down
8 changes: 8 additions & 0 deletions lite/kernels/xpu/compare_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ void CompareCompute<PType, T, Functor>::Run() {
const auto* y = param.Y->template data<T>();

auto& ctx = this->ctx_->template As<XPUContext>();

if (x_dims.size() == 0) {
x_dims.ConstructFrom({1});
}
if (y_dims.size() == 0) {
y_dims.ConstructFrom({1});
}

Functor comp_func;
std::vector<int> xshape;
std::vector<int> yshape;
Expand Down
8 changes: 8 additions & 0 deletions lite/kernels/xpu/concat_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ using concati64 =
paddle::lite::kernels::xpu::ConcatCompute<int64_t, PRECISION(kFloat)>;
using concati8 =
paddle::lite::kernels::xpu::ConcatCompute<int8_t, PRECISION(kInt8)>;
using concatbool =
paddle::lite::kernels::xpu::ConcatCompute<bool, PRECISION(kFloat)>;

REGISTER_LITE_KERNEL(concat, kXPU, kFloat, kNCHW, concatfp32, def)
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kFloat))})
Expand Down Expand Up @@ -147,3 +149,9 @@ REGISTER_LITE_KERNEL(concat, kXPU, kInt8, kNCHW, concati8, concat_INT8)
{LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt32))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt8))})
.Finalize();
REGISTER_LITE_KERNEL(concat, kXPU, kFloat, kNCHW, concatbool, concat_BOOL)
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kBool))})
.BindInput("AxisTensor",
{LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt32))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kBool))})
.Finalize();
35 changes: 31 additions & 4 deletions lite/kernels/xpu/linspace_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ namespace lite {
namespace kernels {
namespace xpu {

template <typename T>
T GetValueOfExpectedType(const lite::Tensor* x) {
switch (x->precision()) {
case PRECISION(kFloat):
return static_cast<T>(x->template data<float>()[0]);
case PRECISION(kInt32):
return static_cast<T>(x->template data<int32_t>()[0]);
case PRECISION(kInt64):
return static_cast<T>(x->template data<int64_t>()[0]);
default:
LOG(FATAL) << "data type is not supported: "
<< lite_api::PrecisionToStr(x->precision());
return static_cast<T>(0);
}
}

template <typename T, PrecisionType PType>
void LinspaceCompute<T, PType>::Run() {
auto& param = this->template Param<operators::LinspaceParam>();
Expand All @@ -31,20 +47,31 @@ void LinspaceCompute<T, PType>::Run() {
auto* out_tensor = param.Out;
int64_t num = static_cast<int64_t>(num_tensor->template data<int>()[0]);
int r = -1;

T start_val = GetValueOfExpectedType<T>(start_tensor);
T stop_val = GetValueOfExpectedType<T>(stop_tensor);
switch (param.Out->precision()) {
case PRECISION(kFloat):
r = xdnn::linspace<T>(ctx.GetRawContext(),
out_tensor->template mutable_data<T>(TARGET(kXPU)),
static_cast<T>(start_tensor->template data<T>()[0]),
static_cast<T>(stop_tensor->template data<T>()[0]),
start_val,
stop_val,
num);
CHECK_EQ(r, 0);
break;
case PRECISION(kInt32):
r = xdnn::linspace<T>(ctx.GetRawContext(),
out_tensor->template mutable_data<T>(TARGET(kXPU)),
static_cast<T>(start_tensor->template data<T>()[0]),
static_cast<T>(stop_tensor->template data<T>()[0]),
start_val,
stop_val,
num);
CHECK_EQ(r, 0);
break;
case PRECISION(kInt64):
r = xdnn::linspace<T>(ctx.GetRawContext(),
out_tensor->template mutable_data<T>(TARGET(kXPU)),
start_val,
stop_val,
num);
CHECK_EQ(r, 0);
break;
Expand Down
2 changes: 1 addition & 1 deletion lite/kernels/xpu/scale_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ using XPUScale_Int64 =
REGISTER_LITE_KERNEL(scale, kXPU, kFloat, kNCHW, XPUScale_Int64, int64)
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt64))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt64))})
.Finalize();
.Finalize();
4 changes: 3 additions & 1 deletion lite/kernels/xpu/topk_v2_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ void TopkV2Compute::Run() {
indices_int32_device,
m,
n,
k);
k,
true,
true);
CHECK_EQ(r, 0);

r = xdnn::cast_v2<int, int64_t>(
Expand Down
2 changes: 1 addition & 1 deletion lite/kernels/xpu/unbind_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ using unbind_int64 =
REGISTER_LITE_KERNEL(unbind, kXPU, kFloat, kNCHW, unbind_int64, int64)
.BindInput("X", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt64))})
.BindOutput("Out", {LiteType::GetTensorTy(TARGET(kXPU), PRECISION(kInt64))})
.Finalize();
.Finalize();
2 changes: 1 addition & 1 deletion lite/kernels/xpu/unbind_compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class UnbindCompute : public KernelLite<TARGET(kXPU), PType> {
} // namespace xpu
} // namespace kernels
} // namespace lite
} // namespace paddle
} // namespace paddle
2 changes: 1 addition & 1 deletion lite/operators/compare_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void GetBroadcastDimsArrays(const DDim &x_dims,
};

CHECK_GE(axis, 0);
CHECK_LT(axis, max_dim);
CHECK_LE(axis, max_dim);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥可以到 max_dim ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int max_dim = (std::max)(dim_x.size(), dim_y.size()); int axis = std::abs(static_cast<int>(dim_x.size() - dim_y.size()));
但是这里出现了dim_x.size() = 0 的情况,导致axis= 1 && max_dim =1,并且x还并不是一个0dim的scalar,暂时没有追到根因,这里先放开一下供业务临时使用,暂不合入

if (x_dims.size() > y_dims.size()) {
std::fill(y_dims_array, y_dims_array + axis, 1);
if (axis + y_dims.size() < max_dim) {
Expand Down