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

Add aten::conj_physical #477

Merged
merged 8 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
29 changes: 29 additions & 0 deletions src/ATen/native/xpu/UnaryOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ATen/xpu/XPUNativeFunctions.h>

#include <ATen/native/xpu/sycl/AbsKernel.h>
#include <ATen/native/xpu/sycl/UnaryComplexKernels.h>
#include <ATen/native/xpu/sycl/UnaryFractionKernels.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAcosKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAcoshKernel.h>
Expand Down Expand Up @@ -515,4 +516,32 @@ Tensor& XPUNativeFunctions::erfc_out(const Tensor& self, Tensor& out) {
return out;
}

Tensor& XPUNativeFunctions::conj_physical_out(const Tensor& self, Tensor& out) {
auto iter = TensorIterator::unary_op(out, self);
native::xpu::conj_physical_kernel(iter);
return out;
}

Tensor XPUNativeFunctions::_conj_physical(const Tensor& self) {
if (self.is_conj()) {
return self.conj().clone();
}
Tensor out;
auto iter = TensorIterator::unary_op(out, self);
native::xpu::conj_physical_kernel(iter);
return iter.output();
}

Tensor XPUNativeFunctions::conj_physical(const Tensor& self) {
if (!self.is_complex())
return self;
return XPUNativeFunctions::_conj_physical(self);
}

Tensor& XPUNativeFunctions::conj_physical_(Tensor& self) {
if (!self.is_complex())
return self;
return XPUNativeFunctions::conj_physical_out(self, self);
}

} // namespace at
1 change: 0 additions & 1 deletion src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"cholesky",
"cholesky_inverse",
"_cholesky_solve_helper",
"conj_physical.out",
"copysign.out",
"cosh.out",
"count_nonzero.dim_IntList",
Expand Down
26 changes: 26 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryComplexKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ void conj_kernel(TensorIterator& iter) {
}));
}

template <typename scalar_t>
struct ConjPhysicalFunctor {
scalar_t operator()(scalar_t z) const {
return std::conj(z);
}
};

template <typename TYPE>
struct ConjPhysicalFunctor<c10::complex<TYPE>> {
c10::complex<TYPE> operator()(c10::complex<TYPE> z) const {
return c10::complex<TYPE>(z.real(), -z.imag());
}
};

void conj_physical_kernel(TensorIterator& iter) {
AT_DISPATCH_SWITCH(
iter.common_dtype(),
"conj_xpu",
AT_DISPATCH_CASE_ALL_TYPES_AND3(kBool, kBFloat16, kHalf, [&] {
// Conj is a no-op for non-complex types
copy_kernel(iter);
}) AT_DISPATCH_CASE_COMPLEX_TYPES_AND(kComplexHalf, [&] {
gpu_kernel(iter, ConjPhysicalFunctor<scalar_t>());
}));
}

template <typename scalar_t>
struct NegConjScalarFunc {
scalar_t operator()(scalar_t src_val) const {
Expand Down
2 changes: 2 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryComplexKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace at::native::xpu {

void conj_kernel(TensorIterator& iter);

void conj_physical_kernel(TensorIterator& iter);

void neg_conj_kernel(TensorIterator& iter);

void neg_kernel(TensorIterator& iter);
Expand Down
9 changes: 4 additions & 5 deletions test/xpu/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,9 +2207,8 @@ def launch_test(test_case, skip_list=None, exe_list=None):
# torch.autograd.gradcheck.GradcheckError: Jacobian computed with forward mode mismatch for output 0 with respect to input 0,
"test_fn_fwgrad_bwgrad_nn_functional_rrelu_xpu_float64",
"test_forward_mode_AD_nn_functional_rrelu_xpu_float64",
# RuntimeError: DispatchStub: unsupported device typexpu
"test_inplace_forward_mode_AD_conj_physical_xpu_complex128",
# NotImplementedError: Could not run 'aten::_to_dense' with arguments from the 'SparseXPU' backend.
"test_forward_mode_AD_conj_physical_xpu_complex128",
# NotImplementedError: Could not run 'aten::_to_dense' with arguments from the 'SparseXPU' backend.
"test_fn_fwgrad_bwgrad_to_sparse_xpu_float64",
"test_forward_mode_AD_to_sparse_xpu_float64",
)
Expand Down Expand Up @@ -2745,8 +2744,8 @@ def launch_test(test_case, skip_list=None, exe_list=None):
### Error #7 in TestBwdGradientsXPU , totally 2 , NotImplementedError: Could not run 'aten::_sparse_coo_tensor_with_dims_and_tensors' with arguments from the 'SparseXPU' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::_sparse_coo_tensor_with_dims_and_tensors' is only available for these backends: [XPU, Meta, SparseCPU, SparseMeta, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradHIP, AutogradXLA, AutogradMPS, AutogradIPU, AutogradXPU, AutogradHPU, AutogradVE, AutogradLazy, AutogradMTIA, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, AutogradMeta, AutogradNestedTensor, Tracer, AutocastCPU, AutocastXPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].
"test_fn_grad_to_sparse_xpu_float64",
"test_fn_gradgrad_to_sparse_xpu_float64",
### Error #8 in TestBwdGradientsXPU , totally 2 , RuntimeError: DispatchStub: unsupported device typexpu
"test_inplace_grad_conj_physical_xpu_complex128",
# torch.autograd.gradcheck.GradcheckError: Jacobian computed with forward mode mismatch for output 0 with respect to input 0,
"test_fn_grad_conj_physical_xpu_complex128",
"test_inplace_gradgrad_conj_physical_xpu_complex128",
)
res += launch_test("test_ops_gradients_xpu.py", skip_list)
Expand Down
4 changes: 4 additions & 0 deletions yaml/xpu_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,7 @@ supported:
- randperm.generator_out
- _amp_foreach_non_finite_check_and_unscale_
- _amp_update_scale_
- _conj_physical
- conj_physical
- conj_physical.out
- conj_physical_
Loading