Skip to content

Commit

Permalink
orlando - for updates of implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
llv22 committed Jul 4, 2022
1 parent dfc985a commit 995b36e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions aten/src/ATen/native/cpu/MaxPooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace native {

namespace {

#if defined(__APPLE__) && defined(__MACH__)
template<typename T>
inline bool isnan_(T x) {
return std::isnan(x);
}
inline bool isnan_(const c10::BFloat16 x) {
return std::isnan(x.x);
}
#endif

template <typename scalar_t>
inline void max_pool1d_kernel(
scalar_t* C10_RESTRICT op,
Expand All @@ -22,7 +32,11 @@ inline void max_pool1d_kernel(
int64_t ij = p.index(kj, oj);
for (; oj < oe; ++oj, ij += p.SJ) {
scalar_t val = ip[ij];
#if defined(__APPLE__) && defined(__MACH__)
bool update_max = isnan_(val) || op[oj] < val;
#else
bool update_max = std::isnan(val) || op[oj] < val;
#endif
op[oj] = update_max ? val : op[oj];
}
}
Expand Down
12 changes: 11 additions & 1 deletion c10/util/safe_numerics.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <type_traits>

// GCC has __builtin_mul_overflow from before it supported __has_builtin
#ifdef _MSC_VER
#if defined(_MSC_VER)
#define C10_HAS_BUILTIN_OVERFLOW() (0)
#include <c10/util/llvmMathExtras.h>
#include <intrin.h>
Expand All @@ -19,7 +19,12 @@ namespace c10 {

C10_ALWAYS_INLINE bool add_overflows(uint64_t a, uint64_t b, uint64_t* out) {
#if C10_HAS_BUILTIN_OVERFLOW()
// https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
#if defined(__APPLE__) && defined(__MACH__)
return __builtin_uaddll_overflow(a, b, out);
#else
return __builtin_add_overflow(a, b, out);
#endif
#else
unsigned long long tmp;
auto carry = _addcarry_u64(0, a, b, &tmp);
Expand All @@ -30,7 +35,12 @@ C10_ALWAYS_INLINE bool add_overflows(uint64_t a, uint64_t b, uint64_t* out) {

C10_ALWAYS_INLINE bool mul_overflows(uint64_t a, uint64_t b, uint64_t* out) {
#if C10_HAS_BUILTIN_OVERFLOW()
// https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
#if defined(__APPLE__) && defined(__MACH__)
return __builtin_umulll_overflow(a, b, out);
#else
return __builtin_mul_overflow(a, b, out);
#endif
#else
*out = a * b;
// This test isnt exact, but avoids doing integer division
Expand Down
2 changes: 2 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ if(BUILD_PYTHON)

# These should fill in the rest of the variables, like versions, but resepct
# the variables we set above
set(CMAKE_PREFIX_PATH "/Users/llv23/opt/miniconda3")
set(Python_ADDITIONAL_VERSIONS ${PYTHON_VERSION} 3.8 3.7)
# set(Python_ADDITIONAL_VERSIONS ${PYTHON_VERSION} 3.8)
find_package(PythonInterp 3.0)
find_package(PythonLibs 3.0)

Expand Down

0 comments on commit 995b36e

Please sign in to comment.