Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

#include <cmath>

using Tensor = exec_aten::Tensor;
using executorch::aten::Tensor;
using executorch::runtime::getLeadingDims;
using executorch::runtime::KernelRuntimeContext;

namespace impl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace impl {
namespace reference {
namespace native {

using Tensor = exec_aten::Tensor;
using executorch::aten::Tensor;
using executorch::runtime::getLeadingDims;
using executorch::runtime::KernelRuntimeContext;

void quantized_linear_out(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace impl {
namespace reference {
namespace native {

using Tensor = exec_aten::Tensor;
using executorch::aten::Tensor;
using executorch::runtime::getLeadingDims;
using executorch::runtime::KernelRuntimeContext;

// The quantized matmul. The quantized matmul accumulates in a wider register,
Expand Down
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
6 changes: 6 additions & 0 deletions kernels/portable/cpu/util/test/broadcast_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ using exec_aten::ScalarType;
using exec_aten::Tensor;
using executorch::runtime::ArrayRef;
using executorch::runtime::testing::TensorFactory;
using torch::executor::broadcast_tensor;
using torch::executor::delinearize_index;
using torch::executor::get_broadcast_target_size;
using torch::executor::linearize_access_indexes;
using torch::executor::tensor_is_broadcastable_to;
using torch::executor::tensors_are_broadcastable_between;

TEST(BroadcastUtilTest, BroadcastTensor) {
TensorFactory<ScalarType::Int> tf;
Expand Down
5 changes: 4 additions & 1 deletion kernels/portable/cpu/util/test/reduce_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ using exec_aten::ArrayRef;
using exec_aten::optional;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using torch::executor::testing::TensorFactory;
using executorch::runtime::testing::TensorFactory;
using torch::executor::apply_over_dim;
using torch::executor::apply_over_dim_list;
using torch::executor::get_out_numel;

void _apply_over_dim(const Tensor& in, const optional<int64_t>& dim) {
int64_t* in_data = in.mutable_data_ptr<int64_t>();
Expand Down
2 changes: 1 addition & 1 deletion kernels/test/custom_kernel_example/my_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
- op: relu.out
kernels:
- arg_meta: null
kernel_name: torch::my_custom_kernel::my_relu_out
kernel_name: my_custom_kernels::my_relu_out
16 changes: 8 additions & 8 deletions kernels/test/custom_kernel_example/op_relu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <executorch/runtime/kernel/kernel_includes.h>
#include <executorch/runtime/platform/assert.h>

namespace torch {
namespace my_custom_kernel {
namespace my_custom_kernels {
namespace native {

using Tensor = exec_aten::Tensor;
using ScalarType = exec_aten::ScalarType;
using executor::Error;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using executorch::runtime::Error;
using executorch::runtime::KernelRuntimeContext;
using executorch::runtime::resize_tensor;
using executorch::runtime::tensors_have_same_shape_and_dtype;

namespace {

Expand Down Expand Up @@ -67,7 +68,7 @@ my_relu_out(KernelRuntimeContext& context, const Tensor& input, Tensor& out) {
resize(out, input.sizes());
ET_KERNEL_CHECK(
context,
executor::tensors_have_same_shape_and_dtype(input, out),
tensors_have_same_shape_and_dtype(input, out),
InvalidArgument,
out);

Expand All @@ -94,5 +95,4 @@ my_relu_out(KernelRuntimeContext& context, const Tensor& input, Tensor& out) {
}

} // namespace native
} // namespace my_custom_kernel
} // namespace torch
} // namespace my_custom_kernels
12 changes: 7 additions & 5 deletions kernels/test/op_add_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <iostream>

using namespace ::testing;
using exec_aten::Scalar;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using executorch::aten::Scalar;
using executorch::aten::ScalarType;
using executorch::aten::Tensor;
using executorch::runtime::testing::TensorFactory;
using torch::executor::testing::SupportedFeatures;
using torch::executor::testing::TensorFactory;
namespace etrt = executorch::runtime;

class OpAddOutKernelTest : public OperatorTest {
protected:
Expand Down Expand Up @@ -63,7 +64,8 @@ class OpAddOutKernelTest : public OperatorTest {
test_add<DTYPE_A, DTYPE_B, ScalarType::Float>();
test_add<DTYPE_A, DTYPE_B, ScalarType::Double>();
// Integral out type is only allowed if both inputs are integral types
if (isIntegralType(DTYPE_A, false) && isIntegralType(DTYPE_B, false)) {
if (etrt::isIntegralType(DTYPE_A, false) &&
etrt::isIntegralType(DTYPE_B, false)) {
test_add<DTYPE_A, DTYPE_B, ScalarType::Int>();
test_add<DTYPE_A, DTYPE_B, ScalarType::Long>();
}
Expand Down
12 changes: 7 additions & 5 deletions kernels/test/op_mul_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
#include <gtest/gtest.h>

using namespace ::testing;
using exec_aten::Scalar;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using executorch::aten::Scalar;
using executorch::aten::ScalarType;
using executorch::aten::Tensor;
using executorch::runtime::testing::TensorFactory;
using torch::executor::testing::SupportedFeatures;
using torch::executor::testing::TensorFactory;
namespace etrt = executorch::runtime;

class OpMulOutTest : public OperatorTest {
protected:
Expand Down Expand Up @@ -61,7 +62,8 @@ class OpMulOutTest : public OperatorTest {
test_mul<DTYPE_A, DTYPE_B, ScalarType::Float>();
test_mul<DTYPE_A, DTYPE_B, ScalarType::Double>();
// Integral out type is only allowed if both inputs are integral types
if (isIntegralType(DTYPE_A, false) && isIntegralType(DTYPE_B, false)) {
if (etrt::isIntegralType(DTYPE_A, false) &&
etrt::isIntegralType(DTYPE_B, false)) {
test_mul<DTYPE_A, DTYPE_B, ScalarType::Int>();
test_mul<DTYPE_A, DTYPE_B, ScalarType::Long>();
}
Expand Down
12 changes: 7 additions & 5 deletions kernels/test/op_sub_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#include <gtest/gtest.h>

using namespace ::testing;
using exec_aten::Scalar;
using exec_aten::ScalarType;
using exec_aten::Tensor;
using executorch::aten::Scalar;
using executorch::aten::ScalarType;
using executorch::aten::Tensor;
using executorch::runtime::testing::TensorFactory;
using torch::executor::testing::SupportedFeatures;
using torch::executor::testing::TensorFactory;
namespace etrt = executorch::runtime;

class OpSubOutTest : public OperatorTest {
protected:
Expand Down Expand Up @@ -60,7 +61,8 @@ class OpSubOutTest : public OperatorTest {
test_sub<DTYPE_A, DTYPE_B, ScalarType::Float>();
test_sub<DTYPE_A, DTYPE_B, ScalarType::Double>();
// Integral out type is only allowed if both inputs are integral types
if (isIntegralType(DTYPE_A, false) && isIntegralType(DTYPE_B, false)) {
if (etrt::isIntegralType(DTYPE_A, false) &&
etrt::isIntegralType(DTYPE_B, false)) {
test_sub<DTYPE_A, DTYPE_B, ScalarType::Int>();
test_sub<DTYPE_A, DTYPE_B, ScalarType::Long>();
}
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
Loading
Loading