-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aten::logical_and/or/xor and variant operators (#529)
- [x] logical_and - [x] logical_or - [x] logical_xor --------- Co-authored-by: Feng Yuan <[email protected]>
- Loading branch information
1 parent
4b6c788
commit 348cd80
Showing
6 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <ATen/ATen.h> | ||
#include <ATen/Dispatch.h> | ||
#include <ATen/native/TensorIterator.h> | ||
|
||
#include <ATen/native/BinaryOps.h> | ||
#include <ATen/native/xpu/sycl/BinaryInternal.h> | ||
#include <ATen/native/xpu/sycl/Loops.h> | ||
|
||
namespace at::native::xpu { | ||
|
||
template <typename scalar_t> | ||
struct LogicalAndFunctor { | ||
bool operator()(scalar_t a, scalar_t b) const { | ||
return a && b; | ||
} | ||
}; | ||
|
||
void logical_and_kernel(TensorIteratorBase& iter) { | ||
auto dtype = iter.common_dtype(); | ||
if (at::isComplexType(dtype)) { | ||
AT_DISPATCH_COMPLEX_TYPES(dtype, "logical_and_xpu", [&]() { | ||
opmath_symmetric_gpu_kernel_with_scalars<scalar_t, bool>( | ||
iter, LogicalAndFunctor<scalar_t>()); | ||
}); | ||
} else { | ||
AT_DISPATCH_ALL_TYPES_AND3( | ||
kHalf, kBool, ScalarType::BFloat16, dtype, "logical_and_xpu", [&]() { | ||
opmath_symmetric_gpu_kernel_with_scalars<scalar_t, bool>( | ||
iter, LogicalAndFunctor<scalar_t>()); | ||
}); | ||
} | ||
} | ||
|
||
template <typename scalar_t> | ||
struct LogicalOrFunctor { | ||
bool operator()(scalar_t a, scalar_t b) const { | ||
return a || b; | ||
} | ||
}; | ||
|
||
void logical_or_kernel(TensorIteratorBase& iter) { | ||
auto dtype = iter.common_dtype(); | ||
if (at::isComplexType(dtype)) { | ||
AT_DISPATCH_COMPLEX_TYPES(dtype, "logical_or_xpu", [&]() { | ||
gpu_kernel_with_scalars(iter, LogicalOrFunctor<scalar_t>()); | ||
}); | ||
} else { | ||
AT_DISPATCH_ALL_TYPES_AND3( | ||
kHalf, kBool, ScalarType::BFloat16, dtype, "logical_or_xpu", [&]() { | ||
opmath_symmetric_gpu_kernel_with_scalars<scalar_t, bool>( | ||
iter, LogicalOrFunctor<scalar_t>()); | ||
}); | ||
} | ||
} | ||
|
||
template <typename scalar_t> | ||
struct LogicalXorFunctor { | ||
bool operator()(scalar_t a, scalar_t b) const { | ||
return bool(a) != bool(b); | ||
} | ||
}; | ||
|
||
void logical_xor_kernel(TensorIteratorBase& iter) { | ||
auto dtype = iter.common_dtype(); | ||
if (at::isComplexType(dtype)) { | ||
AT_DISPATCH_COMPLEX_TYPES(dtype, "logical_xor_xpu", [&]() { | ||
gpu_kernel_with_scalars(iter, LogicalXorFunctor<scalar_t>()); | ||
}); | ||
} else { | ||
AT_DISPATCH_ALL_TYPES_AND3( | ||
kHalf, kBool, ScalarType::BFloat16, dtype, "logical_xor_xpu", [&]() { | ||
opmath_symmetric_gpu_kernel_with_scalars<scalar_t, bool>( | ||
iter, LogicalXorFunctor<scalar_t>()); | ||
}); | ||
} | ||
} | ||
|
||
} // namespace at::native::xpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <ATen/native/TensorIterator.h> | ||
|
||
namespace at::native::xpu { | ||
|
||
void logical_and_kernel(TensorIteratorBase& iter); | ||
|
||
void logical_or_kernel(TensorIteratorBase& iter); | ||
|
||
void logical_xor_kernel(TensorIteratorBase& iter); | ||
|
||
} // namespace at::native::xpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters