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
6 changes: 0 additions & 6 deletions kernels/optimized/blas/BlasKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

#include <array>

namespace torch {
namespace executor {
struct BFloat16;
} // namespace executor
} // namespace torch

namespace executorch {
namespace cpublas {

Expand Down
10 changes: 6 additions & 4 deletions runtime/core/exec_aten/testing_util/tensor_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ bool tensor_lists_are_close(
* These functions must be declared in the original namespaces of their
* associated types so that C++ can find them.
*/
namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* Prints the ScalarType to the stream as a human-readable string.
Expand Down Expand Up @@ -298,7 +299,8 @@ std::ostream& operator<<(std::ostream& os, const Tensor& t) {
return os;
}

} // namespace executor
} // namespace torch
} // namespace etensor
} // namespace runtime
} // namespace executorch

#endif // !USE_ATEN_LIB
14 changes: 8 additions & 6 deletions runtime/core/exec_aten/testing_util/tensor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,25 @@ MATCHER_P(IsListEqualTo, other, "") {
* These functions must be declared in the original namespaces of their
* associated types so that C++ can find them.
*/
namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* Prints the ScalarType to the stream as a human-readable string.
*
* See also executorch::runtime::toString(ScalarType t) in ScalarTypeUtil.h.
*/
std::ostream& operator<<(std::ostream& os, const exec_aten::ScalarType& t);
std::ostream& operator<<(std::ostream& os, const ScalarType& t);

/**
* Prints the Tensor to the stream as a human-readable string.
*/
std::ostream& operator<<(std::ostream& os, const exec_aten::Tensor& t);
std::ostream& operator<<(std::ostream& os, const Tensor& t);

} // namespace executor
} // namespace torch
} // namespace etensor
} // namespace runtime
} // namespace executorch

#endif // !USE_ATEN_LIB

Expand Down
22 changes: 13 additions & 9 deletions runtime/core/portable_type/bfloat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <limits>
#include <ostream>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

namespace internal {
inline float f32_from_bits(uint16_t src) {
Expand All @@ -26,12 +27,6 @@ inline float f32_from_bits(uint16_t src) {
return res;
}

inline uint16_t bits_from_f32(float src) {
uint32_t res = 0;
std::memcpy(&res, &src, sizeof(res));
return res >> 16;
}

inline uint16_t round_to_nearest_even(float src) {
if (std::isnan(src)) {
return UINT16_C(0x7FC0);
Expand Down Expand Up @@ -264,13 +259,22 @@ inline bool operator<(BFloat16& lhs, BFloat16& rhs) {
return float(lhs) < float(rhs);
}

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::BFloat16;
} // namespace executor
} // namespace torch

namespace std {

template <>
class numeric_limits<torch::executor::BFloat16> {
class numeric_limits<executorch::runtime::etensor::BFloat16> {
public:
static constexpr bool is_signed = true;
static constexpr bool is_specialized = true;
Expand Down
18 changes: 16 additions & 2 deletions runtime/core/portable_type/bits_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#pragma once
#include <cstdint>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* bits1x8 is an uninterpreted dtype of a tensor with 1 bit (packed to byte
Expand Down Expand Up @@ -65,5 +66,18 @@ struct alignas(2) bits16 {
explicit bits16(uint16_t val) : val_(val) {}
};

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::bits16;
using ::executorch::runtime::etensor::bits1x8;
using ::executorch::runtime::etensor::bits2x4;
using ::executorch::runtime::etensor::bits4x2;
using ::executorch::runtime::etensor::bits8;
} // namespace executor
} // namespace torch
14 changes: 12 additions & 2 deletions runtime/core/portable_type/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#include <executorch/runtime/core/portable_type/half.h>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* An implementation of complex numbers, compatible with c10/util/complex.h from
Expand All @@ -32,5 +33,14 @@ struct alignas(4) complex<Half> {
Half imag_;
};

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::complex;
} // namespace executor
} // namespace torch
15 changes: 13 additions & 2 deletions runtime/core/portable_type/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#include <executorch/runtime/platform/assert.h>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/// Denotes the specific genre of compute device.
/// Subset of https://github.com/pytorch/pytorch/blob/main/c10/core/Device.h
Expand Down Expand Up @@ -59,5 +60,15 @@ struct Device final {
DeviceIndex index_ = -1;
};

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::Device;
using ::executorch::runtime::etensor::DeviceType;
} // namespace executor
} // namespace torch
62 changes: 40 additions & 22 deletions runtime/core/portable_type/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
#endif // __x86_64__ || _M_X64 || __i386 || _M_IX86
#endif // __GNUC__ || __clang__

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* A half-precision floating point type, compatible with c10/util/Half.h from
Expand Down Expand Up @@ -676,18 +677,26 @@ inline Half operator/(int64_t a, Half b) {

static inline std::ostream& operator<<(
std::ostream& out,
const torch::executor::Half& value) {
const executorch::runtime::etensor::Half& value) {
out << (float)value;
return out;
}

} // namespace etensor
} // namespace runtime
} // namespace executorch
namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::Half;
} // namespace executor
} // namespace torch

namespace std {

template <>
class numeric_limits<torch::executor::Half> {
class numeric_limits<executorch::runtime::etensor::Half> {
public:
static constexpr bool is_specialized = true;
static constexpr bool is_signed = true;
Expand All @@ -714,32 +723,41 @@ class numeric_limits<torch::executor::Half> {
static constexpr auto traps = numeric_limits<float>::traps;
static constexpr auto tinyness_before =
numeric_limits<float>::tinyness_before;
static constexpr torch::executor::Half min() {
return torch::executor::Half(0x0400, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half min() {
return executorch::runtime::etensor::Half(
0x0400, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half lowest() {
return torch::executor::Half(0xFBFF, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half lowest() {
return executorch::runtime::etensor::Half(
0xFBFF, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half max() {
return torch::executor::Half(0x7BFF, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half max() {
return executorch::runtime::etensor::Half(
0x7BFF, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half epsilon() {
return torch::executor::Half(0x1400, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half epsilon() {
return executorch::runtime::etensor::Half(
0x1400, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half round_error() {
return torch::executor::Half(0x3800, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half round_error() {
return executorch::runtime::etensor::Half(
0x3800, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half infinity() {
return torch::executor::Half(0x7C00, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half infinity() {
return executorch::runtime::etensor::Half(
0x7C00, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half quiet_NaN() {
return torch::executor::Half(0x7E00, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half quiet_NaN() {
return executorch::runtime::etensor::Half(
0x7E00, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half signaling_NaN() {
return torch::executor::Half(0x7D00, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half signaling_NaN() {
return executorch::runtime::etensor::Half(
0x7D00, executorch::runtime::etensor::Half::from_bits());
}
static constexpr torch::executor::Half denorm_min() {
return torch::executor::Half(0x0001, torch::executor::Half::from_bits());
static constexpr executorch::runtime::etensor::Half denorm_min() {
return executorch::runtime::etensor::Half(
0x0001, executorch::runtime::etensor::Half::from_bits());
}
};

Expand Down
16 changes: 14 additions & 2 deletions runtime/core/portable_type/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include <new>
#include <utility> // std::forward and other template magic checks

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/// Used to indicate an optional type with uninitialized state.
struct nullopt_t final {
Expand Down Expand Up @@ -177,5 +178,16 @@ class optional final {
bool init_;
};

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::nullopt;
using ::executorch::runtime::etensor::nullopt_t;
using ::executorch::runtime::etensor::optional;
} // namespace executor
} // namespace torch
18 changes: 16 additions & 2 deletions runtime/core/portable_type/qint_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#include <cstdint>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* qint8 is for signed 8 bit quantized Tensors
Expand Down Expand Up @@ -65,5 +66,18 @@ struct alignas(1) quint2x4 {
explicit quint2x4(uint8_t val) : val_(val) {}
};

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::qint32;
using ::executorch::runtime::etensor::qint8;
using ::executorch::runtime::etensor::quint2x4;
using ::executorch::runtime::etensor::quint4x2;
using ::executorch::runtime::etensor::quint8;
} // namespace executor
} // namespace torch
14 changes: 12 additions & 2 deletions runtime/core/portable_type/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include <cstdint>
#include <type_traits>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace etensor {

/**
* Represents a scalar value.
Expand Down Expand Up @@ -109,5 +110,14 @@ ET_DEFINE_SCALAR_TO_METHOD(int64_t, Int)
ET_DEFINE_SCALAR_TO_METHOD(bool, Bool)
#undef ET_DEFINE_SCALAR_TO_METHOD

} // namespace etensor
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::etensor::Scalar;
} // namespace executor
} // namespace torch
Loading
Loading