Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .ci/scripts/check_c10_sync.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: --depth 1? or will the commit checkout not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure --depth 1 will break checking out specific commit. also checked and there's no way to clone just a specific commit

pushd pytorch
git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)"
popd
"$(dirname "${BASH_SOURCE[0]}")"/diff_c10_mirror_with_pytorch.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"$(dirname "${BASH_SOURCE[0]}")"/diff_c10_mirror_with_pytorch.sh
"$(git rev-parse --show-toplevel)/.ci/scripts/diff_c10_mirror_with_pytorch.sh"

mega nit: this implicitly assumes theses scripts will always be adjacent

54 changes: 54 additions & 0 deletions .ci/scripts/compare_dirs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/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

exit_status=0
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_status=1
fi
set -x
done < <(find "$dir1" -type f -print0)

exit $exit_status
8 changes: 8 additions & 0 deletions .ci/scripts/diff_c10_mirror_with_pytorch.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this script for just a single line? Can we just use the line directly in check_c10_sync.sh?

If not, I guess we want to either exec this or set -eu up top

32 changes: 32 additions & 0 deletions .github/workflows/check-c10-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: check-c10-sync

on:
pull_request:
paths:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add runtime/core/portable_type/c10 to this list

- .ci/docker/ci_commit_pins/pytorch.txt
- .ci/scripts/compare_dirs.sh
- .ci/scripts/diff_c10_mirror_with_pytorch.sh
Copy link
Contributor

@jathu jathu Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete — diff_c10_mirror_with_pytorch no longer exists


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given check_c10_sync.sh already handles this, why do we need to do this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops

.ci/scripts/check_c10_sync.sh
2 changes: 1 addition & 1 deletion runtime/core/portable_type/c10/c10/macros/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hip/hip_runtime.h>
#endif

Expand Down
5 changes: 5 additions & 0 deletions runtime/core/portable_type/c10/c10/util/Half.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/portable_type/c10/c10/util/bit_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstring>
#include <type_traits>

#if __has_include(<bit>) && (__cplusplus >= 202002L || (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L))
#if __has_include(<bit>) && (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L)
#include <bit>
#define C10_HAVE_STD_BIT_CAST 1
#else
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/portable_type/c10/c10/util/irange.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +103,7 @@ template <
typename Integer2,
std::enable_if_t<std::is_integral_v<Integer1>, bool> = true,
std::enable_if_t<std::is_integral_v<Integer2>, bool> = true>
integer_range<Integer2> irange(Integer1 begin, Integer2 end) {
constexpr integer_range<Integer2> 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 {
Expand Down
Loading