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 vulkan reshape op (hack) #47252

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions aten/src/ATen/native/vulkan/ops/Shape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <ATen/native/vulkan/ops/Common.h>
#include <torch/library.h>

namespace at {
namespace native {
namespace vulkan {
namespace ops {
namespace {

Tensor view(
const Tensor& self_arg,
IntArrayRef shape) {

return self_arg.cpu().view(shape).vulkan();
}

#ifdef USE_VULKAN_API

TORCH_LIBRARY_IMPL(aten, Vulkan, m) {
m.impl("view", TORCH_FN(view));
}

#endif /* USE_VULKAN_API */

} // namespace
} // namespace ops
} // namespace vulkan
} // namespace native
} // namespace at
20 changes: 20 additions & 0 deletions aten/src/ATen/test/vulkan_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ TEST(VulkanAPITest, avg_pool2d) {
ASSERT_TRUE(check);
}

TEST(VulkanAPITest, reshape) {
const auto a_cpu = at::rand({1,3,2,2}, at::device(at::kCPU).dtype(at::kFloat));
const auto a_vulkan = a_cpu.vulkan();

const auto c_cpu = at::reshape(a_cpu, {2,3,1,2});
const auto c_vulkan = at::reshape(a_vulkan, {2,3,1,2});

ASSERT_TRUE(almostEqual(c_cpu, c_vulkan.cpu()));
}

TEST(VulkanAPITest, reshape_) {
const auto a_cpu = at::rand({1,3,2,2}, at::device(at::kCPU).dtype(at::kFloat));
const auto a_vulkan = a_cpu.vulkan();

a_cpu.reshape({2,3,1,2});
a_vulkan.reshape({2,3,1,2});

ASSERT_TRUE(almostEqual(a_cpu, a_vulkan.cpu()));
}

TEST(VulkanAPITest, copy) {
const auto cpu =
at::rand({13, 17, 37, 19}, at::device(at::kCPU).dtype(at::kFloat));
Expand Down