|
|
@ -27,6 +27,11 @@ struct ModFunctor {
|
|
|
|
inline HOSTDEVICE T operator()(T a, T b) const { return a % b; }
|
|
|
|
inline HOSTDEVICE T operator()(T a, T b) const { return a % b; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
|
|
|
struct ModFunctorFP {
|
|
|
|
|
|
|
|
inline HOSTDEVICE T operator()(T a, T b) const { return std::fmod(a, b); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
void elementwise_mod(const framework::ExecutionContext &ctx,
|
|
|
|
void elementwise_mod(const framework::ExecutionContext &ctx,
|
|
|
|
const framework::Tensor *x, const framework::Tensor *y,
|
|
|
|
const framework::Tensor *x, const framework::Tensor *y,
|
|
|
@ -36,6 +41,15 @@ void elementwise_mod(const framework::ExecutionContext &ctx,
|
|
|
|
ModFunctor<T>(), z);
|
|
|
|
ModFunctor<T>(), z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
|
|
|
|
void elementwise_mod_fp(const framework::ExecutionContext &ctx,
|
|
|
|
|
|
|
|
const framework::Tensor *x, const framework::Tensor *y,
|
|
|
|
|
|
|
|
framework::Tensor *z) {
|
|
|
|
|
|
|
|
int axis = ctx.Attr<int>("axis");
|
|
|
|
|
|
|
|
ElementwiseComputeEx<ModFunctorFP<T>, DeviceContext, T>(ctx, x, y, axis,
|
|
|
|
|
|
|
|
ModFunctorFP<T>(), z);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
class ElementwiseModKernel : public framework::OpKernel<T> {
|
|
|
|
class ElementwiseModKernel : public framework::OpKernel<T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
@ -51,5 +65,20 @@ class ElementwiseModKernel : public framework::OpKernel<T> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename DeviceContext, typename T>
|
|
|
|
|
|
|
|
class ElementwiseModFPKernel : public framework::OpKernel<T> {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void Compute(const framework::ExecutionContext &ctx) const override {
|
|
|
|
|
|
|
|
auto *x = ctx.Input<framework::LoDTensor>("X");
|
|
|
|
|
|
|
|
auto *y = ctx.Input<framework::LoDTensor>("Y");
|
|
|
|
|
|
|
|
auto *z = ctx.Output<framework::LoDTensor>("Out");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
z->mutable_data<T>(ctx.GetPlace());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dtype of x and y is float or double
|
|
|
|
|
|
|
|
elementwise_mod_fp<DeviceContext, T>(ctx, x, y, z);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace operators
|
|
|
|
} // namespace operators
|
|
|
|
} // namespace paddle
|
|
|
|
} // namespace paddle
|
|
|
|