Skip to content

Commit 417f99b

Browse files
committed
init
1 parent 149e23d commit 417f99b

File tree

10 files changed

+98
-18
lines changed

10 files changed

+98
-18
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e6f766c7d750d40603eee3f66c5915bac606b3ea
1+
a0a8eca01a88b01f517559fd3cf565a58c134805

runtime/core/portable_type/c10/c10/util/llvmMathExtras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ constexpr inline bool isShiftedInt(int64_t x) {
370370
template <unsigned N>
371371
constexpr inline std::enable_if_t<(N < 64), bool> isUInt(uint64_t X) {
372372
static_assert(N > 0, "isUInt<0> doesn't make sense");
373-
return X < (UINT64_C(1) << (N));
373+
return X < (UINT64_C(1) << N);
374374
}
375375
template <unsigned N>
376376
constexpr inline std::enable_if_t<N >= 64, bool> isUInt(uint64_t /*X*/) {

runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef C10_MACROS_MACROS_H_
22
#define C10_MACROS_MACROS_H_
3+
4+
#ifdef __cplusplus
35
#include <cassert>
6+
#else
7+
#include <assert.h>
8+
#endif
49

510
/* Main entry for torch/headeronly/macros (used to be c10/macros).
611
*
@@ -139,6 +144,8 @@
139144

140145
#define C10_RESTRICT __restrict
141146

147+
#ifdef __cplusplus
148+
142149
// Simply define the namespace, in case a dependent library want to refer to
143150
// the c10 namespace but not any nontrivial files.
144151
namespace c10 {}
@@ -176,6 +183,8 @@ namespace at::xpu {
176183
using namespace c10::xpu;
177184
} // namespace at::xpu
178185

186+
#endif // __cplusplus
187+
179188
// C10_LIKELY/C10_UNLIKELY
180189
//
181190
// These macros provide parentheses, so you can use these macros as:
@@ -236,7 +245,11 @@ using namespace c10::xpu;
236245

237246
#define C10_ERASE C10_ALWAYS_INLINE C10_ATTR_VISIBILITY_HIDDEN
238247

248+
#ifdef __cplusplus
239249
#include <cstdint>
250+
#else
251+
#include <stdint.h>
252+
#endif
240253

241254
#ifdef __HIPCC__
242255
// Unlike CUDA, HIP requires a HIP header to be included for __host__ to work.
@@ -467,7 +480,7 @@ __host__ __device__
467480
// a non-negligible performance impact even if the assert condition is
468481
// never triggered. We choose to use abort() instead which will still
469482
// terminate the application but without a more useful error message.
470-
#if !defined(C10_USE_ROCM_KERNEL_ASSERT) and defined(USE_ROCM)
483+
#if !defined(C10_USE_ROCM_KERNEL_ASSERT) && defined(USE_ROCM)
471484
#define CUDA_KERNEL_ASSERT(cond) \
472485
if C10_UNLIKELY (!(cond)) { \
473486
abort(); \
@@ -517,9 +530,21 @@ __host__ __device__
517530
__assert_fail( \
518531
#cond, __FILE__, static_cast<unsigned int>(__LINE__), __func__); \
519532
}
520-
#endif // C10_USE_ROCM_KERNEL_ASSERT and USE_ROCM
533+
#endif // C10_USE_ROCM_KERNEL_ASSERT && USE_ROCM
521534
#endif // __APPLE__
522535

536+
// Compile-time switch to control how assertions are logged inside CUDA kernels.
537+
// If C10_CUDA_VERBOSE_ASSERT is defined, CUDA_KERNEL_ASSERT_VERBOSE will
538+
// take addition information passed to the macro and forward them to
539+
// CUDA_KERNEL_ASSERT_PRINTF If C10_CUDA_VERBOSE_ASSERT is not defined,
540+
// CUDA_KERNEL_ASSERT_VERBOSE will behave the same as CUDA_KERNEL_ASSERT.
541+
#ifdef C10_ENABLE_VERBOSE_ASSERT
542+
#define CUDA_KERNEL_ASSERT_VERBOSE(cond, ...) \
543+
CUDA_KERNEL_ASSERT_PRINTF(cond, __VA_ARGS__)
544+
#else
545+
#define CUDA_KERNEL_ASSERT_VERBOSE(cond, ...) CUDA_KERNEL_ASSERT(cond)
546+
#endif
547+
523548
#ifdef __APPLE__
524549
#include <TargetConditionals.h>
525550
#endif
@@ -611,4 +636,59 @@ __host__ __device__
611636
#define C10_RETURN_MOVE_IF_OLD_COMPILER 0
612637
#endif
613638

639+
// The HIDDEN_NAMESPACE_BEGIN and HIDDEN_NAMESPACE_END below
640+
// are needed for maintaining robustness in our header APIs in
641+
// torch/headeronly and torch/csrc/stable under the namespaces
642+
// torch::headeronly and torch::stable respectively. We enforce
643+
// hidden visibility for these APIs because we want to enable
644+
// loading custom extensions compiled against different libtorch
645+
// versions where these APIs may have changed.
646+
647+
// Helper macros to handle 1-3 hidden namespace levels when not windows
648+
#define _HIDDEN_NS_GET_MACRO(_1, _2, _3, NAME, ...) NAME
649+
#define _HIDDEN_NS_1(n1) namespace n1 __attribute__((visibility("hidden"))) {
650+
#define _HIDDEN_NS_2(n1, n2) \
651+
namespace n1 { \
652+
namespace n2 __attribute__((visibility("hidden"))) {
653+
#define _HIDDEN_NS_3(n1, n2, n3) \
654+
namespace n1::n2 { \
655+
namespace n3 __attribute__((visibility("hidden"))) {
656+
657+
// Helper macros to close namespaces when not windows
658+
#define _HIDDEN_NS_END_1(n1) }
659+
#define _HIDDEN_NS_END_N(n1, ...) \
660+
} \
661+
}
662+
663+
// Helper macros to join strs with :: (for win, where symbols are hidden by
664+
// default)
665+
#define _EXPAND(...) __VA_ARGS__
666+
#define _JOIN_GET_MACRO(_1, _2, _3, NAME, ...) NAME
667+
#define _JOIN_NS1(a) a
668+
#define _JOIN_NS2(a, b) a::b
669+
#define _JOIN_NS3(a, b, c) a::b::c
670+
671+
#if !defined(HIDDEN_NAMESPACE_BEGIN)
672+
#if defined(__GNUG__) && !defined(_WIN32)
673+
#define HIDDEN_NAMESPACE_BEGIN(...) \
674+
_HIDDEN_NS_GET_MACRO( \
675+
__VA_ARGS__, _HIDDEN_NS_3, _HIDDEN_NS_2, _HIDDEN_NS_1)(__VA_ARGS__)
676+
#else
677+
#define HIDDEN_NAMESPACE_BEGIN(...) \
678+
namespace _EXPAND(_JOIN_GET_MACRO( \
679+
__VA_ARGS__, _JOIN_NS3, _JOIN_NS2, _JOIN_NS1)(__VA_ARGS__)) {
680+
#endif
681+
#endif
682+
683+
#if !defined(HIDDEN_NAMESPACE_END)
684+
#if defined(__GNUG__) && !defined(_WIN32)
685+
#define HIDDEN_NAMESPACE_END(...) \
686+
_HIDDEN_NS_GET_MACRO( \
687+
__VA_ARGS__, _HIDDEN_NS_END_N, _HIDDEN_NS_END_N, _HIDDEN_NS_END_1)( \
688+
__VA_ARGS__)
689+
#else
690+
#define HIDDEN_NAMESPACE_END(...) }
691+
#endif
692+
#endif
693+
614694
#endif // C10_MACROS_MACROS_H_

runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ inline C10_HOST_DEVICE bool operator<(BFloat16& lhs, BFloat16& rhs) {
395395
C10_CLANG_DIAGNOSTIC_POP()
396396
} // namespace c10
397397

398-
namespace torch::headeronly {
398+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)
399399

400400
namespace detail {
401401
using c10::detail::bits_from_f32;
@@ -415,7 +415,7 @@ using c10::operator/=;
415415
using c10::operator<;
416416
using c10::operator>;
417417
using c10::operator<<;
418-
} // namespace torch::headeronly
418+
HIDDEN_NAMESPACE_END(torch, headeronly)
419419

420420
namespace std {
421421

runtime/core/portable_type/c10/torch/headeronly/util/Half.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ C10_CLANG_DIAGNOSTIC_POP()
698698

699699
} // namespace c10
700700

701-
namespace torch::headeronly {
701+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)
702702

703703
using c10::Half;
704704
using c10::operator+;
@@ -724,7 +724,7 @@ using c10::detail::fp16_ieee_to_fp32_bits;
724724
using c10::detail::fp16_ieee_to_fp32_value;
725725
} // namespace detail
726726

727-
} // namespace torch::headeronly
727+
HIDDEN_NAMESPACE_END(torch, headeronly)
728728

729729
namespace std {
730730

runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ template <typename Limit, typename T>
7979
inline constexpr bool greater_than_max(const T& x) {
8080
constexpr bool can_overflow =
8181
std::numeric_limits<T>::digits > std::numeric_limits<Limit>::digits;
82-
return can_overflow && x > (std::numeric_limits<Limit>::max)();
82+
return can_overflow && x > std::numeric_limits<Limit>::max();
8383
}
8484

8585
#ifdef __GNUC__
@@ -139,10 +139,10 @@ inline constexpr bool less_than_lowest(const T& x) {
139139

140140
C10_CLANG_DIAGNOSTIC_POP()
141141

142-
namespace torch::headeronly {
142+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)
143143
using c10::greater_than_max;
144144
using c10::is_negative;
145145
using c10::less_than_lowest;
146146
using c10::signs_differ;
147147
using c10::signum;
148-
} // namespace torch::headeronly
148+
HIDDEN_NAMESPACE_END(torch, headeronly)

runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#endif // __has_include(<bit>) && (__cplusplus >= 202002L ||
1414
// (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L))
1515

16-
namespace torch::headeronly {
16+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)
1717

1818
#if C10_HAVE_STD_BIT_CAST
1919
using std::bit_cast;
@@ -43,7 +43,7 @@ bit_cast(const From& src) noexcept {
4343
#endif // C10_HAVE_STD_BIT_CAST
4444
#undef C10_HAVE_STD_BIT_CAST
4545

46-
} // namespace torch::headeronly
46+
HIDDEN_NAMESPACE_END(torch, headeronly)
4747

4848
namespace c10 {
4949
using torch::headeronly::bit_cast;

runtime/core/portable_type/c10/torch/headeronly/util/complex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ struct alignas(4) complex<Half> {
590590

591591
} // namespace c10
592592

593-
namespace torch::headeronly {
593+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly)
594594
using c10::complex;
595595
using c10::operator+;
596596
using c10::operator-;
@@ -611,6 +611,6 @@ using c10::complex_literals::operator""_if;
611611
using c10::complex_literals::operator""_id;
612612
} // namespace complex_literals
613613

614-
} // namespace torch::headeronly
614+
HIDDEN_NAMESPACE_END(torch, headeronly)
615615

616616
C10_CLANG_DIAGNOSTIC_POP()

runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <torch/headeronly/util/bit_cast.h>
55
#include <cstdint>
66

7-
namespace torch::headeronly::detail {
7+
HIDDEN_NAMESPACE_BEGIN(torch, headeronly, detail)
88

99
C10_HOST_DEVICE inline float fp32_from_bits(uint32_t w) {
1010
#if defined(__OPENCL_VERSION__)
@@ -30,7 +30,7 @@ C10_HOST_DEVICE inline uint32_t fp32_to_bits(float f) {
3030
#endif
3131
}
3232

33-
} // namespace torch::headeronly::detail
33+
HIDDEN_NAMESPACE_END(torch, headeronly, detail)
3434

3535
namespace c10::detail {
3636
using torch::headeronly::detail::fp32_from_bits;

torch_pin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
TORCH_VERSION = "2.10.0"
2-
NIGHTLY_VERSION = "dev20251015"
2+
NIGHTLY_VERSION = "dev20251104"

0 commit comments

Comments
 (0)