Skip to content
Closed
Changes from all 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
18 changes: 5 additions & 13 deletions aten/src/ATen/native/cuda/Copy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
#include <ATen/native/TensorIterator.h>
#include <ATen/native/cuda/Loops.cuh>
#include <THC/THC.h>
#include <c10/util/TypeCast.h>

namespace at {
namespace native {

using namespace at::cuda;

template <typename dst_t, typename src_t>
void copy_kernel_impl(TensorIterator& iter) {
gpu_kernel(iter, []GPU_LAMBDA(src_t x) -> dst_t {
return c10::static_cast_with_inter_type<dst_t>(x);
});
}

// device-to-device copy, does type conversion
static void copy_device_to_device(TensorIterator& iter, bool non_blocking) {
int64_t numel = iter.numel();
Expand Down Expand Up @@ -66,11 +58,11 @@ static void copy_device_to_device(TensorIterator& iter, bool non_blocking) {
cudaMemcpyDeviceToDevice,
copy_stream));
} else {
AT_DISPATCH_ALL_TYPES_AND2(kHalf, kBool, iter.dtype(0), "copy_", [&] {
using dst_t = scalar_t;
AT_DISPATCH_ALL_TYPES_AND2(kHalf, kBool, iter.dtype(1), "copy_", [&] {
copy_kernel_impl<dst_t, scalar_t>(iter);
});
// this is done intentionally done after build because copy has a "promotion"
// rule that always "promote" to target dtype.
iter.promote_common_dtype();
AT_DISPATCH_ALL_TYPES_AND3(kHalf, kBool, kBFloat16, iter.dtype(0), "copy_", [&] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a PR trying to enable BFloat16 for CUDA:
https://github.com/pytorch/pytorch/pull/27259/files#diff-6684cb81a1865b7d52d9f2f1789cd0ceR68-R70
So I include it in this PR also, so that I can benchmark

gpu_kernel(iter, []GPU_LAMBDA(scalar_t x) { return x; });
});
}

Expand Down