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
4 changes: 2 additions & 2 deletions cmake/external/xpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(XPU_RT_LIB_NAME "libxpurt.so")
if(NOT DEFINED XPU_BASE_URL)
set(XPU_BASE_URL_WITHOUT_DATE
"https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev")
set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220727")
set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220728")
else()
set(XPU_BASE_URL "${XPU_BASE_URL}")
endif()
Expand All @@ -19,7 +19,7 @@ endif()
if(NOT DEFINED XPU_XDNN_BASE_URL)
set(XPU_XDNN_BASE_URL_WITHOUT_DATE
"https://klx-sdk-release-public.su.bcebos.com/xdnn/dev")
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20220727")
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20220728")
else()
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL}")
endif()
Expand Down
10 changes: 10 additions & 0 deletions paddle/fluid/framework/tensor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ void TensorFromVector(const std::vector<T>& src,
size,
reinterpret_cast<const platform::CustomDeviceContext&>(ctx).stream());
}
#endif
#ifdef PADDLE_WITH_XPU
else if (platform::is_xpu_place(dst_place)) { // NOLINT
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#endif
else { // NOLINT
PADDLE_THROW(platform::errors::Unimplemented(
Expand Down Expand Up @@ -381,6 +386,11 @@ inline void TensorFromVector(const std::vector<bool>& src,
reinterpret_cast<const platform::CustomDeviceContext&>(ctx).stream();
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size, stream);
}
#endif
#ifdef PADDLE_WITH_XPU
else if (platform::is_xpu_place(dst_place)) { // NOLINT
memory::Copy(dst_place, dst_ptr, src_place, src_ptr, size);
}
#endif
else { // NOLINT
PADDLE_THROW(platform::errors::Unimplemented(
Expand Down
22 changes: 8 additions & 14 deletions paddle/fluid/operators/detection/generate_proposals_v2_op_xpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,14 @@ static std::pair<Tensor, Tensor> ProposalForOneImage(

// 4. nms
int nms_keep_num = 0;
r = xpu::nms<T>(dev_ctx.x_context(),
proposals_filter.data<T>(),
nullptr,
keep_index.data<int>(),
1,
1,
keep_num,
-1,
nms_thresh,
-1,
0,
&nms_keep_num,
pixel_offset);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "nms");
r = xpu::sorted_nms<T>(dev_ctx.x_context(),
proposals_filter.data<T>(),
keep_index.data<int>(),
nms_keep_num,
keep_num,
nms_thresh,
pixel_offset);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "sorted_nms");
if (post_nms_top_n > 0 && post_nms_top_n < nms_keep_num) {
keep_index.Resize({post_nms_top_n});
} else {
Expand Down
17 changes: 9 additions & 8 deletions paddle/fluid/operators/one_hot_op_xpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <vector>

#include "paddle/fluid/operators/one_hot_op.h"
#include "paddle/fluid/platform/device/device_wrapper.h"

namespace paddle {
namespace operators {
Expand All @@ -28,9 +29,13 @@ template <typename DeviceContext, typename T>
class OneHotXPUKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& context) const override {
auto* in = context.Input<LoDTensor>("X");
const auto* in = context.Input<LoDTensor>("X");
auto* out = context.Output<LoDTensor>("Out");

// get depth from attr
int depth = context.Attr<int>("depth");

// get depth from input tensor
if (context.HasInput("depth_tensor")) {
auto* depth_tensor = context.Input<Tensor>("depth_tensor");
auto* depth_data = depth_tensor->data<int32_t>();
Expand All @@ -50,18 +55,14 @@ class OneHotXPUKernel : public framework::OpKernel<T> {

auto& dev_ctx = context.template device_context<DeviceContext>();
int len = in->numel();
// int one_hot(Context* ctx, const T* x, float* y, int len, int depth, float
// on_value = 1.0f, float off_value = 0.0f);
int ret = xpu::one_hot<T>(dev_ctx.x_context(),
in->data<T>(),
out->mutable_data<float>(context.GetPlace()),
len,
depth);

PADDLE_ENFORCE_EQ(ret,
XPU_SUCCESS,
platform::errors::External(
"XPU one_hot kernel return wrong value[%d %s]",
ret,
XPUAPIErrorMsg[ret]));
PADDLE_ENFORCE_XDNN_SUCCESS(ret, "one_hot");
}
};

Expand Down
20 changes: 20 additions & 0 deletions paddle/fluid/operators/sampling_id_op_xpu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/operators/sampling_id_op.h"

namespace ops = paddle::operators;
REGISTER_OP_XPU_KERNEL(sampling_id,
paddle::operators::SamplingIdKernel<float>,
paddle::operators::SamplingIdKernel<double>);
6 changes: 6 additions & 0 deletions paddle/fluid/platform/device/xpu/xpu2_op_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ XPUOpMap& get_kl2_ops() {
XPUKernelSet({pOpKernelType(vartype::INT64, XPUPlace()),
pOpKernelType(vartype::INT32, XPUPlace()),
pOpKernelType(vartype::FP32, XPUPlace())})},
{"one_hot",
XPUKernelSet({pOpKernelType(vartype::INT32, XPUPlace()),
pOpKernelType(vartype::INT64, XPUPlace())})},
{"one_hot_v2",
XPUKernelSet({pOpKernelType(vartype::INT32, XPUPlace()),
pOpKernelType(vartype::INT64, XPUPlace())})},
Expand Down Expand Up @@ -393,6 +396,9 @@ XPUOpMap& get_kl2_ops() {
{"scatter",
XPUKernelSet({pOpKernelType(vartype::INT64, XPUPlace()),
pOpKernelType(vartype::FP32, XPUPlace())})},
{"sampling_id",
XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace()),
pOpKernelType(vartype::FP64, XPUPlace())})},
{"sgd",
XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace()),
pOpKernelType(vartype::FP16, XPUPlace())})},
Expand Down
Loading