Skip to content

Commit

Permalink
[c++] use constexpr instead of const (pytorch#93267)
Browse files Browse the repository at this point in the history
As discussed in pytorch#93199 (comment).

Pull Request resolved: pytorch#93267
Approved by: https://github.com/Skylion007
  • Loading branch information
khushi-411 authored and pytorchmergebot committed Jan 31, 2023
1 parent f9c08e2 commit aee5f84
Show file tree
Hide file tree
Showing 52 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/AbsKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct AbsFunctor {
}
};

const char abs_name[] = "abs_kernel";
constexpr char abs_name[] = "abs_kernel";
void abs_kernel_cuda(TensorIteratorBase& iter) {
auto dtype = iter.dtype();
if (at::isComplexType(dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/BinaryDivTrueKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace at::native {
namespace binary_internal {

const char div_name[] = "div_kernel";
constexpr char div_name[] = "div_kernel";
void div_true_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (iter.common_dtype() == kComplexHalf) {
Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/native/cuda/BinaryLogicalOpsKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char logical_and_name[] = "logical_and_kernel";
constexpr char logical_and_name[] = "logical_and_kernel";
void logical_and_kernel_cuda(TensorIterator& iter) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down Expand Up @@ -48,7 +48,7 @@ void logical_and_kernel_cuda(TensorIterator& iter) {
}
}

const char logical_or_name[] = "logical_or_kernel";
constexpr char logical_or_name[] = "logical_or_kernel";
void logical_or_kernel_cuda(TensorIterator& iter) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down Expand Up @@ -84,7 +84,7 @@ void logical_or_kernel_cuda(TensorIterator& iter) {
}
}

const char logical_xor_name[] = "logical_xor_kernel";
constexpr char logical_xor_name[] = "logical_xor_kernel";
void logical_xor_kernel_cuda(TensorIterator& iter) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/BinaryMiscBackwardOpsKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace at::native {

const char sigmoid_backward_name[] = "sigmoid_backward";
constexpr char sigmoid_backward_name[] = "sigmoid_backward";
void sigmoid_backward_kernel_cuda(TensorIteratorBase& iter) {
auto dtype = iter.dtype();
if(isComplexType(dtype)) {
Expand Down Expand Up @@ -86,7 +86,7 @@ void logit_backward_kernel_cuda(TensorIteratorBase& iter, const Scalar& eps_scal
});
}

const char tanh_backward_name[] = "tanh_backward";
constexpr char tanh_backward_name[] = "tanh_backward";
void tanh_backward_kernel_cuda(TensorIteratorBase& iter) {
auto dtype = iter.dtype();
if(isComplexType(dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/BinaryMulKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace at::native {

const char mul_name[] = "mul_kernel";
constexpr char mul_name[] = "mul_kernel";
void mul_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (common_dtype == kComplexHalf) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/GcdLcmKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace at::native {

// See note [Jiterator]
const char gcd_name[] = "gcd";
constexpr char gcd_name[] = "gcd";
void gcd_kernel_cuda(TensorIteratorBase& iter) {
#if AT_USE_JITERATOR()
AT_DISPATCH_INTEGRAL_TYPES(iter.common_dtype(), "gcd_cuda", [&]() {
Expand All @@ -33,7 +33,7 @@ void gcd_kernel_cuda(TensorIteratorBase& iter) {
}

// See note [Jiterator]
const char lcm_name[] = "lcm";
constexpr char lcm_name[] = "lcm";
void lcm_kernel_cuda(TensorIteratorBase& iter) {
#if AT_USE_JITERATOR()
AT_DISPATCH_INTEGRAL_TYPES(iter.common_dtype(), "lcm_cuda", [&]() {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/Lerp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace at::native {
namespace {

const char lerp_tensor_name[] = "lerp_tensor";
constexpr char lerp_tensor_name[] = "lerp_tensor";
void lerp_tensor_kernel(at::TensorIteratorBase& iter) {
auto dtype = iter.common_dtype();
if(at::isComplexType(dtype)) {
Expand Down Expand Up @@ -63,7 +63,7 @@ void lerp_tensor_kernel(at::TensorIteratorBase& iter) {
}
}

const char lerp_scalar_name[] = "lerp_scalar";
constexpr char lerp_scalar_name[] = "lerp_scalar";
void lerp_scalar_kernel(at::TensorIteratorBase& iter, const c10::Scalar& weight) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/PointwiseOpsKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char addcmul_name[] = "addcmul";
constexpr char addcmul_name[] = "addcmul";
void addcmul_cuda_kernel(TensorIteratorBase& iter, const Scalar& value) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down Expand Up @@ -56,7 +56,7 @@ void addcmul_cuda_kernel(TensorIteratorBase& iter, const Scalar& value) {
}

// return a + alpha * (b / static_cast<accscalar_t>(c));
const char addcdiv_name[] = "addcdiv";
constexpr char addcdiv_name[] = "addcdiv";
void addcdiv_cuda_kernel(TensorIteratorBase& iter, const Scalar& value) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/PowKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void pow_scalar_tensor_impl(TensorIteratorBase& iter, c10::complex<value_t> base
}

/* complex<Half> support impl */
const char pow_scalar_base_name[] = "pow_scalar_base_kernel";
constexpr char pow_scalar_base_name[] = "pow_scalar_base_kernel";
template <>
void pow_scalar_tensor_impl(TensorIteratorBase& iter, c10::complex<at::Half> base) {
using scalar_t = c10::complex<at::Half>;
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace {

#if AT_USE_JITERATOR()
/* complex<Half> support impl */
const char pow_name[] = "pow_kernel";
constexpr char pow_name[] = "pow_kernel";
static const auto pow_kernel_string =
jiterator_stringify(template <typename T> T pow_kernel(T base, T exp) {
return std::pow(base, exp);
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/ReduceSumProdKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct sum_functor {
};

// jiterated specialization for `complex<Half>`
const char sum_name[] = "sum";
constexpr char sum_name[] = "sum";
template <>
struct sum_functor<c10::complex<at::Half>> {
// jiterator reduction fails on windows
Expand Down Expand Up @@ -57,7 +57,7 @@ struct nansum_functor {
}
};

const char prod_name[] = "prod";
constexpr char prod_name[] = "prod";

template <typename scalar_t, typename acc_t = scalar_t, typename out_t = scalar_t>
struct prod_functor {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/UnaryComplexKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ __host__ __device__ static inline c10::complex<T> angle_wrapper(c10::complex<T>
return c10::complex<T>{std::arg(v), 0};
}

const char angle_name[] = "angle_kernel";
constexpr char angle_name[] = "angle_kernel";
void angle_kernel_cuda(TensorIteratorBase& iter) {
auto dtype = iter.common_dtype();
if (at::isComplexType(dtype)) {
Expand Down Expand Up @@ -60,7 +60,7 @@ void angle_kernel_cuda(TensorIteratorBase& iter) {
}

// NB: Ignores the negative bit on tensors
const char conj_name[] = "conj_kernel";
constexpr char conj_name[] = "conj_kernel";
void conj_kernel_cuda(TensorIteratorBase& iter) {
auto conj_chalf = [&] {
using scalar_t = c10::complex<at::Half>;
Expand Down
8 changes: 4 additions & 4 deletions aten/src/ATen/native/cuda/UnaryGammaKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace at::native {

// See note [Jiterator]
const char digamma_name[] = "digamma";
constexpr char digamma_name[] = "digamma";
void digamma_kernel_cuda(TensorIteratorBase& iter) {
#if AT_USE_JITERATOR()
AT_DISPATCH_FLOATING_TYPES_AND_HALF(iter.common_dtype(), "digamma_cuda", [&]() {
Expand All @@ -32,7 +32,7 @@ void digamma_kernel_cuda(TensorIteratorBase& iter) {
}

// See note [Jiterator]
const char trigamma_name[] = "trigamma";
constexpr char trigamma_name[] = "trigamma";
void trigamma_kernel_cuda(TensorIteratorBase& iter) {
#if AT_USE_JITERATOR()
AT_DISPATCH_FLOATING_TYPES_AND_HALF(iter.common_dtype(), "trigamma_cuda", [&]() {
Expand All @@ -50,7 +50,7 @@ void trigamma_kernel_cuda(TensorIteratorBase& iter) {
#endif // AT_USE_JITERATOR()
}

const char polygamma_name[] = "polygamma";
constexpr char polygamma_name[] = "polygamma";
void polygamma_kernel_cuda(TensorIteratorBase& iter, int64_t n) {
if (n == 0) {
digamma_kernel_cuda(iter);
Expand Down Expand Up @@ -83,7 +83,7 @@ void polygamma_kernel_cuda(TensorIteratorBase& iter, int64_t n) {
}
}

const char lgamma_name[] = "lgamma_kernel";
constexpr char lgamma_name[] = "lgamma_kernel";
void lgamma_kernel_cuda(TensorIteratorBase& iter) {
#if AT_USE_JITERATOR()
AT_DISPATCH_FLOATING_TYPES_AND_HALF(iter.common_dtype(), "lgamma_cuda", [&]() {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAcosKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char acos_name[] = "acos";
constexpr char acos_name[] = "acos";
void acos_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAcoshKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char acosh_name[] = "acosh";
constexpr char acosh_name[] = "acosh";
void acosh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if(at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAsinKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char asin_name[] = "asin";
constexpr char asin_name[] = "asin";
void asin_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAsinhKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char asinh_name[] = "asinh";
constexpr char asinh_name[] = "asinh";
void asinh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAtanKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char atan_name[] = "atan";
constexpr char atan_name[] = "atan";
void atan_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricAtanhKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char atanh_name[] = "atanh";
constexpr char atanh_name[] = "atanh";
void atanh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricCosKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char cos_name[] = "cos";
constexpr char cos_name[] = "cos";
void cos_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricCoshKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char cosh_name[] = "cosh";
constexpr char cosh_name[] = "cosh";
void cosh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricSinKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char sin_name[] = "sin";
constexpr char sin_name[] = "sin";
void sin_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricSinhKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char sinh_name[] = "sinh";
constexpr char sinh_name[] = "sinh";
void sinh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricTanKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char tan_name[] = "tan";
constexpr char tan_name[] = "tan";
void tan_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/UnaryGeometricTanhKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace at::native {

const char tanh_name[] = "tanh";
constexpr char tanh_name[] = "tanh";
void tanh_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/native/cuda/UnaryLogKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace at::native {

const char log_name[] = "log_kernel";
constexpr char log_name[] = "log_kernel";
void log_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down Expand Up @@ -44,7 +44,7 @@ void log_kernel_cuda(TensorIteratorBase& iter) {
}
}

const char log10_name[] = "log10_kernel";
constexpr char log10_name[] = "log10_kernel";
void log10_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down Expand Up @@ -81,7 +81,7 @@ void log1p_kernel_cuda(TensorIteratorBase& iter) {
});
}

const char log2_name[] = "log2_kernel";
constexpr char log2_name[] = "log2_kernel";
void log2_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/native/cuda/UnaryOpsKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void bitwise_not_kernel_cuda(TensorIteratorBase& iter) {
}
}

const char exp_name[] = "exp_kernel";
constexpr char exp_name[] = "exp_kernel";
void exp_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down Expand Up @@ -92,7 +92,7 @@ C10_HOST_DEVICE static inline c10::complex<T> rsqrt_wrapper(c10::complex<T> v) {
return one / ::sqrt(v);
}

const char rsqrt_name[] = "rsqrt_kernel";
constexpr char rsqrt_name[] = "rsqrt_kernel";
void rsqrt_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down Expand Up @@ -131,7 +131,7 @@ void rsqrt_kernel_cuda(TensorIteratorBase& iter) {
}
}

const char sqrt_name[] = "sqrt_kernel";
constexpr char sqrt_name[] = "sqrt_kernel";
void sqrt_kernel_cuda(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/UnarySignKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void logical_not_kernel_cuda(TensorIteratorBase& iter) {
}

// NB: Ignores the negative bit on tensors
const char neg_name[] = "neg_kernel";
constexpr char neg_name[] = "neg_kernel";
void neg_kernel_cuda(TensorIteratorBase& iter) {
auto dtype = iter.dtype();
if (at::isComplexType(dtype)) {
Expand Down Expand Up @@ -96,7 +96,7 @@ C10_HOST_DEVICE static inline c10::complex<T> sgn_wrapper(c10::complex<T> z) {
}
}

const char sgn_name[] = "sgn_kernel";
constexpr char sgn_name[] = "sgn_kernel";
void sgn_kernel_cuda(TensorIteratorBase& iter){
auto dtype = iter.dtype();
#if AT_USE_JITERATOR()
Expand Down
Loading

0 comments on commit aee5f84

Please sign in to comment.