forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReduceLogicKernel.cu
38 lines (33 loc) · 1.21 KB
/
ReduceLogicKernel.cu
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
#define TORCH_ASSERT_NO_OPERATORS
#include <ATen/native/TensorIterator.h>
#include <ATen/native/cuda/Reduce.cuh>
#include <ATen/native/DispatchStub.h>
#include <ATen/native/SharedReduceOps.h>
#include <ATen/native/ReduceOps.h>
#include <ATen/Dispatch.h>
namespace at { namespace native {
void and_kernel_cuda(TensorIterator& iter) {
AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND3(
kHalf, kBFloat16, kBool, iter.common_dtype(), "and_cuda", [&]() {
gpu_reduce_kernel<scalar_t, bool>(
iter,
func_wrapper<bool>([] GPU_LAMBDA(scalar_t a, scalar_t b) -> bool {
return (static_cast<bool>(a) && static_cast<bool>(b));
}),
true);
});
}
void or_kernel_cuda(TensorIterator& iter) {
AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND3(
kHalf, kBFloat16, kBool, iter.common_dtype(), "or_cuda", [&]() {
gpu_reduce_kernel<scalar_t, bool>(
iter,
func_wrapper<bool>([] GPU_LAMBDA(scalar_t a, scalar_t b) -> bool {
return (static_cast<bool>(a) || static_cast<bool>(b));
}),
false);
});
}
REGISTER_DISPATCH(and_stub, &and_kernel_cuda);
REGISTER_DISPATCH(or_stub, &or_kernel_cuda);
}} // namespace at::native