#include "op_plugin/AclOpsInterface.h"
#include "op_plugin/OpApiInterface.h"
#include "op_plugin/utils/op_api_common.h"
namespace op_api {
using npu_preparation = at_npu::native::OpPreparation;
static const int64_t SIZE_INT64 = 8;
static at::Tensor remainder_dest_output(const at::Tensor& self, const at::Tensor& other)
{
bool isSelfWrapped = !torch_npu::utils::is_npu(self);
return isSelfWrapped ? other : self;
}
at::Tensor& remainder_out(const at::Tensor& self, const at::Scalar& other, at::Tensor& out)
{
DO_COMPATIBILITY(aclnnRemainderTensorScalar, acl_op::remainder_out(self, other, out));
npu_preparation::check_tensor({self}, out, out.scalar_type(), self.sizes());
EXEC_NPU_CMD(aclnnRemainderTensorScalar, self, other, out);
return out;
}
at::Tensor remainder(const at::Tensor& self, const at::Scalar& other)
{
DO_COMPATIBILITY(aclnnRemainderTensorScalar, acl_op::remainder(self, other));
at::ScalarType result_type = at::native::result_type(self, other);
at::Tensor result = npu_preparation::apply_tensor(self, self.options().dtype(result_type));
EXEC_NPU_CMD(aclnnRemainderTensorScalar, self, other, result);
return result;
}
at::Tensor& remainder_(at::Tensor& self, const at::Scalar& other)
{
DO_COMPATIBILITY(aclnnInplaceRemainderTensorScalar, acl_op::remainder_(self, other));
EXEC_NPU_CMD(aclnnInplaceRemainderTensorScalar, self, other);
return self;
}
at::Tensor remainder(const at::Scalar& self, const at::Tensor& other)
{
at::ScalarType result_type = at::native::result_type(self, other);
at::Tensor result = npu_preparation::apply_tensor(other, other.options().dtype(result_type));
EXEC_NPU_CMD(aclnnRemainderScalarTensor, self, other, result);
return result;
}
at::Tensor& remainder_out(const at::Tensor& self, const at::Tensor& other, at::Tensor& out)
{
DO_COMPATIBILITY(aclnnRemainderTensorTensor, acl_op::remainder_out(self, other, out));
auto broadcast_shape = op_infer::broadcast_ops_npu_output_size(self, other);
npu_preparation::check_tensor({self, other}, out, out.scalar_type(), broadcast_shape);
if (npu_preparation::IsCPUScalar(self)) {
const at::Scalar self_scalar = self.item();
EXEC_NPU_CMD(aclnnRemainderScalarTensor, self_scalar, other, out);
} else if (npu_preparation::IsCPUScalar(other)) {
const at::Scalar other_scalar = other.item();
EXEC_NPU_CMD(aclnnRemainderTensorScalar, self, other_scalar, out);
} else {
EXEC_NPU_CMD(aclnnRemainderTensorTensor, self, other, out);
}
return out;
}
at::Tensor remainder(const at::Tensor& self, const at::Tensor& other)
{
DO_COMPATIBILITY(aclnnRemainderTensorTensor, acl_op::remainder(self, other));
at::Tensor output_tensor = remainder_dest_output(self, other);
auto output_size = op_infer::broadcast_ops_npu_output_size(self, other);
at::ScalarType result_type = at::native::result_type(self, other);
at::Tensor result = npu_preparation::apply_tensor(output_size, output_tensor.options().dtype(result_type),
output_tensor);
if (npu_preparation::IsCPUScalar(self)) {
const at::Scalar self_scalar = self.item();
EXEC_NPU_CMD(aclnnRemainderScalarTensor, self_scalar, other, result);
} else if (npu_preparation::IsCPUScalar(other)) {
const at::Scalar other_scalar = other.item();
EXEC_NPU_CMD(aclnnRemainderTensorScalar, self, other_scalar, result);
} else {
EXEC_NPU_CMD(aclnnRemainderTensorTensor, self, other, result);
}
return result;
}
at::Tensor& remainder_(at::Tensor& self, const at::Tensor& other)
{
DO_COMPATIBILITY(aclnnInplaceRemainderTensorTensor, acl_op::remainder_(self, other));
if (npu_preparation::IsCPUScalar(other)) {
const at::Scalar other_scalar = other.item();
return op_api::remainder_(self, other_scalar);
}
at::ScalarType promote_type = at::native::result_type(self, other);
EXEC_NPU_CMD(aclnnInplaceRemainderTensorTensor, self, other);
return self;
}
}