Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions include/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BSD License

For "ExecuTorch" software

Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright 2023 Arm Limited and/or its affiliates.
Copyright (c) Qualcomm Innovation Center, Inc.
Copyright (c) 2023 Apple Inc.
Copyright (c) 2024 MediaTek Inc.
Copyright 2023 NXP
Copyright (c) 2025 Samsung Electronics Co. LTD
Copyright (c) Intel Corporation

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name Meta nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions include/c10/macros/Export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/macros/Export.h>
1 change: 1 addition & 0 deletions include/c10/macros/Macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/macros/Macros.h>
1 change: 1 addition & 0 deletions include/c10/util/BFloat16-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/util/BFloat16.h>
3 changes: 3 additions & 0 deletions include/c10/util/BFloat16-math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include <torch/headeronly/util/BFloat16-math.h>
1 change: 1 addition & 0 deletions include/c10/util/BFloat16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/util/BFloat16.h>
1 change: 1 addition & 0 deletions include/c10/util/Half-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/util/Half.h>
8 changes: 8 additions & 0 deletions include/c10/util/Half.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <torch/headeronly/util/Half.h>

// need to keep the following for BC because the APIs in here were exposed
// before migrating Half to torch/headeronly
#if (defined(CPU_CAPABILITY_AVX2) || defined(CPU_CAPABILITY_AVX512)) && \
!defined(__APPLE__)
#include <ATen/cpu/vec/vec_half.h>
#endif
1 change: 1 addition & 0 deletions include/c10/util/TypeSafeSignMath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/util/TypeSafeSignMath.h>
1 change: 1 addition & 0 deletions include/c10/util/bit_cast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <torch/headeronly/util/bit_cast.h>
73 changes: 73 additions & 0 deletions include/c10/util/complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#include <complex>

#include <c10/macros/Macros.h>
#include <c10/util/Half.h>
#include <torch/headeronly/util/complex.h>

// std functions
//
// The implementation of these functions also follow the design of C++20

namespace std {

template <typename T>
constexpr T real(const c10::complex<T>& z) {
return z.real();
}

template <typename T>
constexpr T imag(const c10::complex<T>& z) {
return z.imag();
}

template <typename T>
C10_HOST_DEVICE T abs(const c10::complex<T>& z) {
#if defined(__CUDACC__) || defined(__HIPCC__)
return thrust::abs(static_cast<thrust::complex<T>>(z));
#else
return std::abs(static_cast<std::complex<T>>(z));
#endif
}

template <typename T>
C10_HOST_DEVICE T arg(const c10::complex<T>& z) {
return std::atan2(std::imag(z), std::real(z));
}

template <typename T>
constexpr T norm(const c10::complex<T>& z) {
return z.real() * z.real() + z.imag() * z.imag();
}

// For std::conj, there are other versions of it:
// constexpr std::complex<float> conj( float z );
// template< class DoubleOrInteger >
// constexpr std::complex<double> conj( DoubleOrInteger z );
// constexpr std::complex<long double> conj( long double z );
// These are not implemented
// TODO(@zasdfgbnm): implement them as c10::conj
template <typename T>
constexpr c10::complex<T> conj(const c10::complex<T>& z) {
return c10::complex<T>(z.real(), -z.imag());
}

// Thrust does not have complex --> complex version of thrust::proj,
// so this function is not implemented at c10 right now.
// TODO(@zasdfgbnm): implement it by ourselves

// There is no c10 version of std::polar, because std::polar always
// returns std::complex. Use c10::polar instead;

} // namespace std

#define C10_INTERNAL_INCLUDE_COMPLEX_REMAINING_H
// math functions are included in a separate file
#include <c10/util/complex_math.h> // IWYU pragma: keep
#undef C10_INTERNAL_INCLUDE_COMPLEX_REMAINING_H

namespace c10 {
using torch::headeronly::is_complex;
using torch::headeronly::scalar_value_type;
} // namespace c10
Loading
Loading