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::maxunpool2d and aten::maxunpool3d #856

Merged
merged 17 commits into from
Oct 24, 2024
Merged
59 changes: 59 additions & 0 deletions src/ATen/native/xpu/MaxUnpooling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <ATen/ATen.h>
#include <ATen/AccumulateType.h>
#include <ATen/core/Tensor.h>
#include <ATen/core/op_registration/adaption.h>
#include <ATen/native/layer_norm.h>
#include <ATen/native/xpu/sycl/MaxUnpoolingKernels.h>

#ifndef AT_PER_OPERATOR_HEADERS
#include <ATen/Functions.h>
#include <ATen/NativeFunctions.h>
#else
#include <ATen/ops/empty.h>
#endif

namespace at::native {

xytintel marked this conversation as resolved.
Show resolved Hide resolved
Tensor& max_unpooling2d_forward_out_xpu(
const Tensor& self,
const Tensor& indices,
IntArrayRef output_size,
Tensor& out) {
native::xpu::max_unpooling2d_forward_kernel(out, self, indices, output_size);
return out;
}

Tensor max_unpooling2d_forward_xpu(
const Tensor& self,
const Tensor& indices,
IntArrayRef output_size) {
auto out = at::empty({0}, self.options());
max_unpooling2d_forward_out_xpu(self, indices, output_size, out);
return out;
}

Tensor& max_unpooling3d_forward_out_xpu(
const Tensor& self,
const Tensor& indices,
IntArrayRef output_size,
IntArrayRef stride,
IntArrayRef padding,
Tensor& out) {
native::xpu::max_unpooling3d_forward_kernel(
out, self, indices, output_size, stride, padding);
return out;
}

Tensor max_unpooling3d_forward_xpu(
const Tensor& self,
const Tensor& indices,
IntArrayRef output_size,
IntArrayRef stride,
IntArrayRef padding) {
auto out = at::empty({0}, self.options());
max_unpooling3d_forward_out_xpu(
self, indices, output_size, stride, padding, out);
return out;
}

} // namespace at::native
2 changes: 0 additions & 2 deletions src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"lu_unpack.out",
"max_pool3d_with_indices",
"max_pool3d_with_indices_backward",
"max_unpool2d",
"max_unpool3d",
"multilabel_margin_loss_backward",
"multilabel_margin_loss_forward",
"multi_margin_loss",
Expand Down
13 changes: 13 additions & 0 deletions src/ATen/native/xpu/sycl/KernelUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <c10/util/Exception.h>
#include <limits>

#define XPU_KERNEL_LOOP_TYPE(item, i, n, index_type) \
int64_t _i_n_d_e_x = \
item.get_group(0) * item.get_local_range(0) + item.get_local_id(0); \
for (index_type i = _i_n_d_e_x; _i_n_d_e_x < (n); \
_i_n_d_e_x += item.get_local_range(0) * item.get_group_range(0), \
i = _i_n_d_e_x)

#define XPU_KERNEL_LOOP(item, i, n) XPU_KERNEL_LOOP_TYPE(item, i, n, int)
Loading
Loading