forked from facebookarchive/fbcuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemoryAccess.cuh
56 lines (44 loc) · 1.84 KB
/
MemoryAccess.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
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include "cuda/DeviceTensor.cuh"
using namespace facebook::cuda;
namespace facebook { namespace cuda {
__device__ inline bool inBounds(
int x, int padL, const DeviceTensor<float, 2>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(x - padL) < (unsigned)(t.getSize(1)));
}
__device__ inline bool inBounds(
int y, int x, int padU, int padL, const DeviceTensor<float, 3>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(y - padU) < (unsigned)(t.getSize(1)) &&
(unsigned)(x - padL) < (unsigned)(t.getSize(2)));
}
__device__ __forceinline__ bool inBounds(
int y, int x, int padU, int padL, const DeviceTensor<float, 4>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(y - padU) < (unsigned)(t.getSize(2)) &&
(unsigned)(x - padL) < (unsigned)(t.getSize(3)));
}
__device__ inline bool inBounds(
int x, const DeviceTensor<float, 2>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(x) < (unsigned)(t.getSize(1)));
}
__device__ inline bool inBounds(int y, int x, const DeviceTensor<float, 3>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(y) < (unsigned)(t.getSize(1)) &&
(unsigned)(x) < (unsigned)(t.getSize(2)));
}
__device__ inline bool inBounds(int y, int x, const DeviceTensor<float, 4>& t) {
// Rely on unsigned integer arithmetic to test both 0 <= and < t.getSize()
// in one shot.
return ((unsigned)(y) < (unsigned)(t.getSize(2)) &&
(unsigned)(x) < (unsigned)(t.getSize(3)));
}
}} // ns