|
|
|
@ -47,19 +47,6 @@ class ConcatXPUKernel : public framework::OpKernel<T> {
|
|
|
|
|
"size is %d.",
|
|
|
|
|
axis, ins[0]->dims().size()));
|
|
|
|
|
|
|
|
|
|
auto place = ctx.GetPlace();
|
|
|
|
|
out->mutable_data<T>(place);
|
|
|
|
|
std::vector<int> choose_idx;
|
|
|
|
|
int n = 0;
|
|
|
|
|
for (unsigned int i = 0; i < ins.size(); ++i) {
|
|
|
|
|
if (ins[i] && ins[i]->numel() > 0) {
|
|
|
|
|
choose_idx.push_back(i);
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PADDLE_ENFORCE_GT(
|
|
|
|
|
n, 0, platform::errors::InvalidArgument("No tensor need concat?"));
|
|
|
|
|
|
|
|
|
|
// If axis is 0, the lod of the output is not the same as inputs.
|
|
|
|
|
if (axis == 0 && ins[0]->lod().size() > 0) {
|
|
|
|
|
size_t lod_size_0 = ins[0]->lod().size();
|
|
|
|
@ -87,30 +74,32 @@ class ConcatXPUKernel : public framework::OpKernel<T> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto input_dims = ins[0]->dims();
|
|
|
|
|
std::vector<std::vector<int>> xdims_list(n);
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
std::vector<int> tmp_dims(input_dims.size());
|
|
|
|
|
for (int j = 0; j < input_dims.size(); ++j) {
|
|
|
|
|
tmp_dims[j] = ins[i]->dims()[j];
|
|
|
|
|
auto place = ctx.GetPlace();
|
|
|
|
|
out->mutable_data<T>(place);
|
|
|
|
|
std::vector<std::vector<int>> xdims_list;
|
|
|
|
|
std::vector<const T*> ptrs;
|
|
|
|
|
for (unsigned int i = 0; i < ins.size(); ++i) {
|
|
|
|
|
if (ins[i] && ins[i]->numel() > 0) {
|
|
|
|
|
ptrs.push_back(ins[i]->data<T>());
|
|
|
|
|
int size = ins[i]->dims().size();
|
|
|
|
|
std::vector<int> tmp_dims(size);
|
|
|
|
|
for (int j = 0; j < size; ++j) {
|
|
|
|
|
tmp_dims[j] = ins[i]->dims()[j];
|
|
|
|
|
}
|
|
|
|
|
xdims_list.push_back(tmp_dims);
|
|
|
|
|
}
|
|
|
|
|
xdims_list[i] = tmp_dims;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PADDLE_ENFORCE_GT(xdims_list.size(), 0, platform::errors::InvalidArgument(
|
|
|
|
|
"No tensor need concat"));
|
|
|
|
|
auto& dev_ctx = ctx.template device_context<DeviceContext>();
|
|
|
|
|
std::vector<const T*> ptrs;
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
ptrs.push_back(ins[choose_idx[i]]->data<T>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int r = xpu::concat<T>(dev_ctx.x_context(), ptrs, out->data<T>(),
|
|
|
|
|
xdims_list, axis);
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
r, XPU_SUCCESS,
|
|
|
|
|
platform::errors::External(
|
|
|
|
|
"XPU API return wrong value[%d], please check whether "
|
|
|
|
|
"Baidu Kunlun Card is properly installed.",
|
|
|
|
|
r));
|
|
|
|
|
PADDLE_ENFORCE_EQ(r, XPU_SUCCESS,
|
|
|
|
|
platform::errors::External(
|
|
|
|
|
"XPU concat kernel return wrong value[%d %s]", r,
|
|
|
|
|
XPUAPIErrorMsg[r]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|