From 3c1552cf19638c3ba68efa790fbd9849096724fa Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Apr 2025 10:34:19 -0700 Subject: [PATCH 1/4] Update [ghstack-poisoned] --- runtime/core/portable_type/c10/c10/macros/Macros.h | 2 +- runtime/core/portable_type/c10/c10/util/Half.h | 5 +++++ runtime/core/portable_type/c10/c10/util/bit_cast.h | 2 +- runtime/core/portable_type/c10/c10/util/irange.h | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime/core/portable_type/c10/c10/macros/Macros.h b/runtime/core/portable_type/c10/c10/macros/Macros.h index 1429eda2acb..919eb6c8567 100644 --- a/runtime/core/portable_type/c10/c10/macros/Macros.h +++ b/runtime/core/portable_type/c10/c10/macros/Macros.h @@ -241,7 +241,7 @@ using namespace c10::xpu; #ifdef __HIPCC__ // Unlike CUDA, HIP requires a HIP header to be included for __host__ to work. // We do this #include here so that C10_HOST_DEVICE and friends will Just Work. -// See https://github.com/ROCm/hip/issues/441 +// See https://github.com/ROCm-Developer-Tools/HIP/issues/441 #include #endif diff --git a/runtime/core/portable_type/c10/c10/util/Half.h b/runtime/core/portable_type/c10/c10/util/Half.h index b77cf7b1f4a..373881f21e5 100644 --- a/runtime/core/portable_type/c10/c10/util/Half.h +++ b/runtime/core/portable_type/c10/c10/util/Half.h @@ -243,7 +243,12 @@ C10_HOST_DEVICE inline float fp16_ieee_to_fp32_value(uint16_t h) { // const float exp_scale = 0x1.0p-112f; constexpr uint32_t scale_bits = (uint32_t)15 << 23; float exp_scale_val = 0; +#if defined(_MSC_VER) && defined(__clang__) + __builtin_memcpy(&exp_scale_val, &scale_bits, sizeof(exp_scale_val)); +#else std::memcpy(&exp_scale_val, &scale_bits, sizeof(exp_scale_val)); +#endif + const float exp_scale = exp_scale_val; const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale; diff --git a/runtime/core/portable_type/c10/c10/util/bit_cast.h b/runtime/core/portable_type/c10/c10/util/bit_cast.h index c1d2c102886..380cfa7db1c 100644 --- a/runtime/core/portable_type/c10/c10/util/bit_cast.h +++ b/runtime/core/portable_type/c10/c10/util/bit_cast.h @@ -3,7 +3,7 @@ #include #include -#if __has_include() && (__cplusplus >= 202002L || (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L)) +#if __has_include() && (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) #include #define C10_HAVE_STD_BIT_CAST 1 #else diff --git a/runtime/core/portable_type/c10/c10/util/irange.h b/runtime/core/portable_type/c10/c10/util/irange.h index 81104d9568f..f5310510099 100644 --- a/runtime/core/portable_type/c10/c10/util/irange.h +++ b/runtime/core/portable_type/c10/c10/util/irange.h @@ -24,7 +24,7 @@ struct integer_iterator { using pointer = I*; using reference = I&; - explicit constexpr integer_iterator(I value_) : value(value_) {} + explicit constexpr integer_iterator(I value) : value(value) {} constexpr I operator*() const { return value; @@ -103,7 +103,7 @@ template < typename Integer2, std::enable_if_t, bool> = true, std::enable_if_t, bool> = true> -integer_range irange(Integer1 begin, Integer2 end) { +constexpr integer_range irange(Integer1 begin, Integer2 end) { // If end<=begin then the range is empty; we can achieve this effect by // choosing the larger of {begin, end} as the loop terminator return { From 0e3df0a2e0cc61b56468f977bb598b8caf823ab4 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Apr 2025 10:34:23 -0700 Subject: [PATCH 2/4] Update [ghstack-poisoned] --- .ci/scripts/check_c10_sync.sh | 13 +++++ .ci/scripts/compare_dirs.sh | 53 +++++++++++++++++++++ .ci/scripts/diff_c10_mirror_with_pytorch.sh | 8 ++++ .github/workflows/check_c10_sync.yml | 32 +++++++++++++ 4 files changed, 106 insertions(+) create mode 100755 .ci/scripts/check_c10_sync.sh create mode 100755 .ci/scripts/compare_dirs.sh create mode 100755 .ci/scripts/diff_c10_mirror_with_pytorch.sh create mode 100644 .github/workflows/check_c10_sync.yml diff --git a/.ci/scripts/check_c10_sync.sh b/.ci/scripts/check_c10_sync.sh new file mode 100755 index 00000000000..1b4b2aabdf6 --- /dev/null +++ b/.ci/scripts/check_c10_sync.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set -exu +ls pytorch/.git || git clone https://github.com/pytorch/pytorch.git +pushd pytorch +git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)" +popd +"$(dirname "${BASH_SOURCE[0]}")"/diff_c10_mirror_with_pytorch.sh diff --git a/.ci/scripts/compare_dirs.sh b/.ci/scripts/compare_dirs.sh new file mode 100755 index 00000000000..a50cd855c2e --- /dev/null +++ b/.ci/scripts/compare_dirs.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set -eux + +# Check if dir1's files are also found in dir2 with the same +# contents. Exempt files named BUCK, CMakeLists.txt, TARGETS, or +# targets.bzl. + +if [ $# -ne 2 ]; then + echo "Usage: $0 dir1 dir2" >&2 + exit 1 +fi +dir1="$1" +dir2="$2" + +if [ ! -d "$dir1" ] || [ ! -d "$dir2" ]; then + echo "Error: Both directories must exist" >&2 + exit 1 +fi + +while IFS= read -r -d '' file; do + base=$(basename "$file") + case "$base" in + "BUCK"|"CMakeLists.txt"|"TARGETS"|"targets.bzl") + continue + ;; + esac + # Construct the corresponding path in the second directory + file2="$dir2/${file#$dir1/}" + # Check if the corresponding file exists in the second directory + if [ ! -f "$file2" ]; then + echo "Error: File '$file' found in '$dir1' but not found in '$dir2'" >&2 + exit 1 + fi + # Compare the contents of the two files using diff + set +ex + differences=$(diff -u -p "$file" "$file2") + set -e # leave x off + # If there are any differences, print an error message and exit with failure status + if [ -n "$differences" ]; then + echo "Error: Mismatch detected in file '$file':" >&2 + echo "$differences" >&2 + exit 1 + fi + set -x +done < <(find "$dir1" -type f -print0) +# If no mismatches were found, exit with success status +exit 0 diff --git a/.ci/scripts/diff_c10_mirror_with_pytorch.sh b/.ci/scripts/diff_c10_mirror_with_pytorch.sh new file mode 100755 index 00000000000..f0694fe8503 --- /dev/null +++ b/.ci/scripts/diff_c10_mirror_with_pytorch.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +$(dirname "${BASH_SOURCE[0]}")/compare_dirs.sh runtime/core/portable_type/c10/c10 pytorch/c10 diff --git a/.github/workflows/check_c10_sync.yml b/.github/workflows/check_c10_sync.yml new file mode 100644 index 00000000000..e224d0fe36b --- /dev/null +++ b/.github/workflows/check_c10_sync.yml @@ -0,0 +1,32 @@ +name: check-c10-sync + +on: + pull_request: + paths: + - .ci/docker/ci_commit_pins/pytorch.txt + - .ci/scripts/compare_dirs.sh + - .ci/scripts/diff_c10_mirror_with_pytorch.sh + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }} + cancel-in-progress: true + +jobs: + check-c10-sync: + permissions: + id-token: write + contents: read + name: check-c10-sync + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Clone PyTorch + run: | + set -ex + git clone https://github.com/pytorch/pytorch.git + pushd pytorch || return + git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)" + popd + .ci/scripts/diff_c10_mirror_with_pytorch.sh From c2540c1225b7e201ade166e5fc50899cdeaf9eb5 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Apr 2025 12:40:45 -0700 Subject: [PATCH 3/4] Update [ghstack-poisoned] --- .github/workflows/{check_c10_sync.yml => check-c10-sync.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{check_c10_sync.yml => check-c10-sync.yml} (94%) diff --git a/.github/workflows/check_c10_sync.yml b/.github/workflows/check-c10-sync.yml similarity index 94% rename from .github/workflows/check_c10_sync.yml rename to .github/workflows/check-c10-sync.yml index e224d0fe36b..cca4a6bf2f2 100644 --- a/.github/workflows/check_c10_sync.yml +++ b/.github/workflows/check-c10-sync.yml @@ -29,4 +29,4 @@ jobs: pushd pytorch || return git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)" popd - .ci/scripts/diff_c10_mirror_with_pytorch.sh + .ci/scripts/check_c10_sync.sh From ae01ff1e31d1752c8c67af859a7fbbc46aa9cd6b Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 23 Apr 2025 12:42:42 -0700 Subject: [PATCH 4/4] Update [ghstack-poisoned] --- .ci/scripts/compare_dirs.sh | 7 ++++--- runtime/core/portable_type/c10/c10/macros/Macros.h | 2 +- runtime/core/portable_type/c10/c10/util/Half.h | 5 ----- runtime/core/portable_type/c10/c10/util/bit_cast.h | 2 +- runtime/core/portable_type/c10/c10/util/irange.h | 4 ++-- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.ci/scripts/compare_dirs.sh b/.ci/scripts/compare_dirs.sh index a50cd855c2e..6b6e3a6cc93 100755 --- a/.ci/scripts/compare_dirs.sh +++ b/.ci/scripts/compare_dirs.sh @@ -23,6 +23,7 @@ if [ ! -d "$dir1" ] || [ ! -d "$dir2" ]; then exit 1 fi +exit_status=0 while IFS= read -r -d '' file; do base=$(basename "$file") case "$base" in @@ -45,9 +46,9 @@ while IFS= read -r -d '' file; do if [ -n "$differences" ]; then echo "Error: Mismatch detected in file '$file':" >&2 echo "$differences" >&2 - exit 1 + exit_status=1 fi set -x done < <(find "$dir1" -type f -print0) -# If no mismatches were found, exit with success status -exit 0 + +exit $exit_status diff --git a/runtime/core/portable_type/c10/c10/macros/Macros.h b/runtime/core/portable_type/c10/c10/macros/Macros.h index 919eb6c8567..1429eda2acb 100644 --- a/runtime/core/portable_type/c10/c10/macros/Macros.h +++ b/runtime/core/portable_type/c10/c10/macros/Macros.h @@ -241,7 +241,7 @@ using namespace c10::xpu; #ifdef __HIPCC__ // Unlike CUDA, HIP requires a HIP header to be included for __host__ to work. // We do this #include here so that C10_HOST_DEVICE and friends will Just Work. -// See https://github.com/ROCm-Developer-Tools/HIP/issues/441 +// See https://github.com/ROCm/hip/issues/441 #include #endif diff --git a/runtime/core/portable_type/c10/c10/util/Half.h b/runtime/core/portable_type/c10/c10/util/Half.h index 373881f21e5..b77cf7b1f4a 100644 --- a/runtime/core/portable_type/c10/c10/util/Half.h +++ b/runtime/core/portable_type/c10/c10/util/Half.h @@ -243,12 +243,7 @@ C10_HOST_DEVICE inline float fp16_ieee_to_fp32_value(uint16_t h) { // const float exp_scale = 0x1.0p-112f; constexpr uint32_t scale_bits = (uint32_t)15 << 23; float exp_scale_val = 0; -#if defined(_MSC_VER) && defined(__clang__) - __builtin_memcpy(&exp_scale_val, &scale_bits, sizeof(exp_scale_val)); -#else std::memcpy(&exp_scale_val, &scale_bits, sizeof(exp_scale_val)); -#endif - const float exp_scale = exp_scale_val; const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale; diff --git a/runtime/core/portable_type/c10/c10/util/bit_cast.h b/runtime/core/portable_type/c10/c10/util/bit_cast.h index 380cfa7db1c..c1d2c102886 100644 --- a/runtime/core/portable_type/c10/c10/util/bit_cast.h +++ b/runtime/core/portable_type/c10/c10/util/bit_cast.h @@ -3,7 +3,7 @@ #include #include -#if __has_include() && (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) +#if __has_include() && (__cplusplus >= 202002L || (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L)) #include #define C10_HAVE_STD_BIT_CAST 1 #else diff --git a/runtime/core/portable_type/c10/c10/util/irange.h b/runtime/core/portable_type/c10/c10/util/irange.h index f5310510099..81104d9568f 100644 --- a/runtime/core/portable_type/c10/c10/util/irange.h +++ b/runtime/core/portable_type/c10/c10/util/irange.h @@ -24,7 +24,7 @@ struct integer_iterator { using pointer = I*; using reference = I&; - explicit constexpr integer_iterator(I value) : value(value) {} + explicit constexpr integer_iterator(I value_) : value(value_) {} constexpr I operator*() const { return value; @@ -103,7 +103,7 @@ template < typename Integer2, std::enable_if_t, bool> = true, std::enable_if_t, bool> = true> -constexpr integer_range irange(Integer1 begin, Integer2 end) { +integer_range irange(Integer1 begin, Integer2 end) { // If end<=begin then the range is empty; we can achieve this effect by // choosing the larger of {begin, end} as the loop terminator return {