forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForeachUtils.cuh
56 lines (45 loc) · 1.33 KB
/
ForeachUtils.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <ATen/ATen.h>
#include <ATen/native/cuda/Loops.cuh>
#include <ATen/native/cuda/MemoryAccess.cuh>
namespace at {
namespace native {
namespace {
static constexpr int64_t kILP = 4;
static constexpr int64_t kChunkSize = 65536;
static constexpr int64_t kBlockSize = 512;
template<typename T>
__device__ __forceinline__ bool is_aligned(T* p){
return ((uint64_t)p) % (kILP * sizeof(T)) == 0;
}
template<typename T>
__device__ __forceinline__ void load_store(T* dst, T* src, int dst_offset, int src_offset){
using LT = at::native::memory::aligned_vector<T, kILP>;
((LT*)dst)[dst_offset] = ((LT*)src)[src_offset];
}
}
bool check_fast_route(TensorList tensors, Scalar scalar) {
TORCH_CHECK(tensors.size() > 0, "Tensor list must have at least one tensor.");
auto expected_dtype = tensors[0].dtype();
auto expected_device = tensors[0].device();
for (auto t : tensors) {
if (t.dtype() != expected_dtype) {
return false;
}
if (t.device() != expected_device) {
return false;
}
if (t.layout() != at::kStrided) {
return false;
}
if (!t.is_non_overlapping_and_dense()) {
return false;
}
if ((at::isIntegralType(t.scalar_type(), true) && scalar.isFloatingPoint()) ||
t.scalar_type() == at::kBool) {
return false;
}
}
return true;
}
}} // at::native