Skip to content

Commit

Permalink
s/exec_aten::/executorch::aten::/ for runtime/**/*.h (#6161)
Browse files Browse the repository at this point in the history
s/exec_aten::/executorch::aten::/ for runtime/**/*.h (#6030)

Summary:
Pull Request resolved: #6030

Migrate all runtime headers to use the new aten namespace, so that they act as good examples for users. The .cpp code can migrate later.

Reviewed By: lucylq

Differential Revision: D64078576

fbshipit-source-id: fe011d0ff16b0beaa278944312a62760e51b945c
(cherry picked from commit 84f51d1)

Co-authored-by: Dave Bort <[email protected]>
  • Loading branch information
pytorchbot and dbort authored Oct 11, 2024
1 parent 99827e4 commit 7d1b0a1
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 282 deletions.
155 changes: 84 additions & 71 deletions runtime/core/evalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct evalue_to_const_ref_overload_return {
};

template <>
struct evalue_to_const_ref_overload_return<exec_aten::Tensor> {
using type = const exec_aten::Tensor&;
struct evalue_to_const_ref_overload_return<executorch::aten::Tensor> {
using type = const executorch::aten::Tensor&;
};

template <typename T>
Expand All @@ -36,8 +36,8 @@ struct evalue_to_ref_overload_return {
};

template <>
struct evalue_to_ref_overload_return<exec_aten::Tensor> {
using type = exec_aten::Tensor&;
struct evalue_to_ref_overload_return<executorch::aten::Tensor> {
using type = executorch::aten::Tensor&;
};

} // namespace internal
Expand Down Expand Up @@ -67,18 +67,19 @@ class BoxedEvalueList {
/*
* Constructs and returns the list of T specified by the EValue pointers
*/
exec_aten::ArrayRef<T> get() const;
executorch::aten::ArrayRef<T> get() const;

private:
// Source of truth for the list
exec_aten::ArrayRef<EValue*> wrapped_vals_;
executorch::aten::ArrayRef<EValue*> wrapped_vals_;
// Same size as wrapped_vals
mutable T* unwrapped_vals_;
};

template <>
exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>
BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const;
executorch::aten::ArrayRef<executorch::aten::optional<executorch::aten::Tensor>>
BoxedEvalueList<executorch::aten::optional<executorch::aten::Tensor>>::get()
const;

// Aggregate typing system similar to IValue only slimmed down with less
// functionality, no dependencies on atomic, and fewer supported types to better
Expand All @@ -96,18 +97,18 @@ struct EValue {
bool as_bool;
// TODO(jakeszwe): convert back to pointers to optimize size of this
// struct
exec_aten::ArrayRef<char> as_string;
exec_aten::ArrayRef<double> as_double_list;
exec_aten::ArrayRef<bool> as_bool_list;
executorch::aten::ArrayRef<char> as_string;
executorch::aten::ArrayRef<double> as_double_list;
executorch::aten::ArrayRef<bool> as_bool_list;
BoxedEvalueList<int64_t> as_int_list;
BoxedEvalueList<exec_aten::Tensor> as_tensor_list;
BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>
BoxedEvalueList<executorch::aten::Tensor> as_tensor_list;
BoxedEvalueList<executorch::aten::optional<executorch::aten::Tensor>>
as_list_optional_tensor;
} copyable_union;

// Since a Tensor just holds a TensorImpl*, there's no value to use Tensor*
// here.
exec_aten::Tensor as_tensor;
executorch::aten::Tensor as_tensor;

Payload() {}
~Payload() {}
Expand Down Expand Up @@ -197,7 +198,7 @@ struct EValue {

/****** Scalar Type ******/
/// Construct an EValue using the implicit value of a Scalar.
/*implicit*/ EValue(exec_aten::Scalar s) {
/*implicit*/ EValue(executorch::aten::Scalar s) {
if (s.isIntegral(false)) {
tag = Tag::Int;
payload.copyable_union.as_int = s.to<int64_t>();
Expand All @@ -216,7 +217,7 @@ struct EValue {
return tag == Tag::Int || tag == Tag::Double || tag == Tag::Bool;
}

exec_aten::Scalar toScalar() const {
executorch::aten::Scalar toScalar() const {
// Convert from implicit value to Scalar using implicit constructors.

if (isDouble()) {
Expand All @@ -231,11 +232,11 @@ struct EValue {
}

/****** Tensor Type ******/
/*implicit*/ EValue(exec_aten::Tensor t) : tag(Tag::Tensor) {
/*implicit*/ EValue(executorch::aten::Tensor t) : tag(Tag::Tensor) {
// When built in aten mode, at::Tensor has a non trivial constructor
// destructor, so regular assignment to a union field is UB. Instead we must
// go through placement new (which causes a refcount bump).
new (&payload.as_tensor) exec_aten::Tensor(t);
new (&payload.as_tensor) executorch::aten::Tensor(t);
}

// Template constructor that allows construction from types that can be
Expand All @@ -261,35 +262,36 @@ struct EValue {
return tag == Tag::Tensor;
}

exec_aten::Tensor toTensor() && {
executorch::aten::Tensor toTensor() && {
ET_CHECK_MSG(isTensor(), "EValue is not a Tensor.");
auto res = std::move(payload.as_tensor);
clearToNone();
return res;
}

exec_aten::Tensor& toTensor() & {
executorch::aten::Tensor& toTensor() & {
ET_CHECK_MSG(isTensor(), "EValue is not a Tensor.");
return payload.as_tensor;
}

const exec_aten::Tensor& toTensor() const& {
const executorch::aten::Tensor& toTensor() const& {
ET_CHECK_MSG(isTensor(), "EValue is not a Tensor.");
return payload.as_tensor;
}

/****** String Type ******/
/*implicit*/ EValue(const char* s, size_t size) : tag(Tag::String) {
payload.copyable_union.as_string = exec_aten::ArrayRef<char>(s, size);
payload.copyable_union.as_string =
executorch::aten::ArrayRef<char>(s, size);
}

bool isString() const {
return tag == Tag::String;
}

exec_aten::string_view toString() const {
executorch::aten::string_view toString() const {
ET_CHECK_MSG(isString(), "EValue is not a String.");
return exec_aten::string_view(
return executorch::aten::string_view(
payload.copyable_union.as_string.data(),
payload.copyable_union.as_string.size());
}
Expand All @@ -303,41 +305,42 @@ struct EValue {
return tag == Tag::ListInt;
}

exec_aten::ArrayRef<int64_t> toIntList() const {
executorch::aten::ArrayRef<int64_t> toIntList() const {
ET_CHECK_MSG(isIntList(), "EValue is not an Int List.");
return payload.copyable_union.as_int_list.get();
}

/****** Bool List Type ******/
/*implicit*/ EValue(exec_aten::ArrayRef<bool> b) : tag(Tag::ListBool) {
/*implicit*/ EValue(executorch::aten::ArrayRef<bool> b) : tag(Tag::ListBool) {
payload.copyable_union.as_bool_list = b;
}

bool isBoolList() const {
return tag == Tag::ListBool;
}

exec_aten::ArrayRef<bool> toBoolList() const {
executorch::aten::ArrayRef<bool> toBoolList() const {
ET_CHECK_MSG(isBoolList(), "EValue is not a Bool List.");
return payload.copyable_union.as_bool_list;
}

/****** Double List Type ******/
/*implicit*/ EValue(exec_aten::ArrayRef<double> d) : tag(Tag::ListDouble) {
/*implicit*/ EValue(executorch::aten::ArrayRef<double> d)
: tag(Tag::ListDouble) {
payload.copyable_union.as_double_list = d;
}

bool isDoubleList() const {
return tag == Tag::ListDouble;
}

exec_aten::ArrayRef<double> toDoubleList() const {
executorch::aten::ArrayRef<double> toDoubleList() const {
ET_CHECK_MSG(isDoubleList(), "EValue is not a Double List.");
return payload.copyable_union.as_double_list;
}

/****** Tensor List Type ******/
/*implicit*/ EValue(BoxedEvalueList<exec_aten::Tensor> t)
/*implicit*/ EValue(BoxedEvalueList<executorch::aten::Tensor> t)
: tag(Tag::ListTensor) {
payload.copyable_union.as_tensor_list = t;
}
Expand All @@ -346,13 +349,14 @@ struct EValue {
return tag == Tag::ListTensor;
}

exec_aten::ArrayRef<exec_aten::Tensor> toTensorList() const {
executorch::aten::ArrayRef<executorch::aten::Tensor> toTensorList() const {
ET_CHECK_MSG(isTensorList(), "EValue is not a Tensor List.");
return payload.copyable_union.as_tensor_list.get();
}

/****** List Optional Tensor Type ******/
/*implicit*/ EValue(BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>> t)
/*implicit*/ EValue(
BoxedEvalueList<executorch::aten::optional<executorch::aten::Tensor>> t)
: tag(Tag::ListOptionalTensor) {
payload.copyable_union.as_list_optional_tensor = t;
}
Expand All @@ -361,34 +365,39 @@ struct EValue {
return tag == Tag::ListOptionalTensor;
}

exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>
executorch::aten::ArrayRef<
executorch::aten::optional<executorch::aten::Tensor>>
toListOptionalTensor() const {
return payload.copyable_union.as_list_optional_tensor.get();
}

/****** ScalarType Type ******/
exec_aten::ScalarType toScalarType() const {
executorch::aten::ScalarType toScalarType() const {
ET_CHECK_MSG(isInt(), "EValue is not a ScalarType.");
return static_cast<exec_aten::ScalarType>(payload.copyable_union.as_int);
return static_cast<executorch::aten::ScalarType>(
payload.copyable_union.as_int);
}

/****** MemoryFormat Type ******/
exec_aten::MemoryFormat toMemoryFormat() const {
executorch::aten::MemoryFormat toMemoryFormat() const {
ET_CHECK_MSG(isInt(), "EValue is not a MemoryFormat.");
return static_cast<exec_aten::MemoryFormat>(payload.copyable_union.as_int);
return static_cast<executorch::aten::MemoryFormat>(
payload.copyable_union.as_int);
}

/****** Layout Type ******/
exec_aten::Layout toLayout() const {
executorch::aten::Layout toLayout() const {
ET_CHECK_MSG(isInt(), "EValue is not a Layout.");
return static_cast<exec_aten::Layout>(payload.copyable_union.as_int);
return static_cast<executorch::aten::Layout>(payload.copyable_union.as_int);
}

/****** Device Type ******/
exec_aten::Device toDevice() const {
executorch::aten::Device toDevice() const {
ET_CHECK_MSG(isInt(), "EValue is not a Device.");
return exec_aten::Device(
static_cast<exec_aten::DeviceType>(payload.copyable_union.as_int), -1);
return executorch::aten::Device(
static_cast<executorch::aten::DeviceType>(
payload.copyable_union.as_int),
-1);
}

template <typename T>
Expand All @@ -403,9 +412,9 @@ struct EValue {
* an uninitialized state.
*/
template <typename T>
inline exec_aten::optional<T> toOptional() const {
inline executorch::aten::optional<T> toOptional() const {
if (this->isNone()) {
return exec_aten::nullopt;
return executorch::aten::nullopt;
}
return this->to<T>();
}
Expand All @@ -421,7 +430,7 @@ struct EValue {
void moveFrom(EValue&& rhs) noexcept {
if (rhs.isTensor()) {
new (&payload.as_tensor)
exec_aten::Tensor(std::move(rhs.payload.as_tensor));
executorch::aten::Tensor(std::move(rhs.payload.as_tensor));
rhs.payload.as_tensor.~Tensor();
} else {
payload.copyable_union = rhs.payload.copyable_union;
Expand Down Expand Up @@ -451,7 +460,7 @@ struct EValue {

EValue(const Payload& p, Tag t) : tag(t) {
if (isTensor()) {
new (&payload.as_tensor) exec_aten::Tensor(p.as_tensor);
new (&payload.as_tensor) executorch::aten::Tensor(p.as_tensor);
} else {
payload.copyable_union = p.copyable_union;
}
Expand Down Expand Up @@ -480,60 +489,64 @@ struct EValue {
return static_cast<return_type>(this->method_name()); \
}

EVALUE_DEFINE_TO(exec_aten::Scalar, toScalar)
EVALUE_DEFINE_TO(executorch::aten::Scalar, toScalar)
EVALUE_DEFINE_TO(int64_t, toInt)
EVALUE_DEFINE_TO(bool, toBool)
EVALUE_DEFINE_TO(double, toDouble)
EVALUE_DEFINE_TO(exec_aten::string_view, toString)
EVALUE_DEFINE_TO(exec_aten::ScalarType, toScalarType)
EVALUE_DEFINE_TO(exec_aten::MemoryFormat, toMemoryFormat)
EVALUE_DEFINE_TO(exec_aten::Layout, toLayout)
EVALUE_DEFINE_TO(exec_aten::Device, toDevice)
EVALUE_DEFINE_TO(executorch::aten::string_view, toString)
EVALUE_DEFINE_TO(executorch::aten::ScalarType, toScalarType)
EVALUE_DEFINE_TO(executorch::aten::MemoryFormat, toMemoryFormat)
EVALUE_DEFINE_TO(executorch::aten::Layout, toLayout)
EVALUE_DEFINE_TO(executorch::aten::Device, toDevice)
// Tensor and Optional Tensor
EVALUE_DEFINE_TO(
exec_aten::optional<exec_aten::Tensor>,
toOptional<exec_aten::Tensor>)
EVALUE_DEFINE_TO(exec_aten::Tensor, toTensor)
executorch::aten::optional<executorch::aten::Tensor>,
toOptional<executorch::aten::Tensor>)
EVALUE_DEFINE_TO(executorch::aten::Tensor, toTensor)

// IntList and Optional IntList
EVALUE_DEFINE_TO(exec_aten::ArrayRef<int64_t>, toIntList)
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<int64_t>, toIntList)
EVALUE_DEFINE_TO(
exec_aten::optional<exec_aten::ArrayRef<int64_t>>,
toOptional<exec_aten::ArrayRef<int64_t>>)
executorch::aten::optional<executorch::aten::ArrayRef<int64_t>>,
toOptional<executorch::aten::ArrayRef<int64_t>>)

// DoubleList and Optional DoubleList
EVALUE_DEFINE_TO(exec_aten::ArrayRef<double>, toDoubleList)
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<double>, toDoubleList)
EVALUE_DEFINE_TO(
exec_aten::optional<exec_aten::ArrayRef<double>>,
toOptional<exec_aten::ArrayRef<double>>)
executorch::aten::optional<executorch::aten::ArrayRef<double>>,
toOptional<executorch::aten::ArrayRef<double>>)

// BoolList and Optional BoolList
EVALUE_DEFINE_TO(exec_aten::ArrayRef<bool>, toBoolList)
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<bool>, toBoolList)
EVALUE_DEFINE_TO(
exec_aten::optional<exec_aten::ArrayRef<bool>>,
toOptional<exec_aten::ArrayRef<bool>>)
executorch::aten::optional<executorch::aten::ArrayRef<bool>>,
toOptional<executorch::aten::ArrayRef<bool>>)

// TensorList and Optional TensorList
EVALUE_DEFINE_TO(exec_aten::ArrayRef<exec_aten::Tensor>, toTensorList)
EVALUE_DEFINE_TO(
exec_aten::optional<exec_aten::ArrayRef<exec_aten::Tensor>>,
toOptional<exec_aten::ArrayRef<exec_aten::Tensor>>)
executorch::aten::ArrayRef<executorch::aten::Tensor>,
toTensorList)
EVALUE_DEFINE_TO(
executorch::aten::optional<
executorch::aten::ArrayRef<executorch::aten::Tensor>>,
toOptional<executorch::aten::ArrayRef<executorch::aten::Tensor>>)

// List of Optional Tensor
EVALUE_DEFINE_TO(
exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>,
executorch::aten::ArrayRef<
executorch::aten::optional<executorch::aten::Tensor>>,
toListOptionalTensor)
#undef EVALUE_DEFINE_TO

template <typename T>
exec_aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
for (typename exec_aten::ArrayRef<T>::size_type i = 0;
executorch::aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
for (typename executorch::aten::ArrayRef<T>::size_type i = 0;
i < wrapped_vals_.size();
i++) {
ET_CHECK(wrapped_vals_[i] != nullptr);
unwrapped_vals_[i] = wrapped_vals_[i]->template to<T>();
}
return exec_aten::ArrayRef<T>{unwrapped_vals_, wrapped_vals_.size()};
return executorch::aten::ArrayRef<T>{unwrapped_vals_, wrapped_vals_.size()};
}

} // namespace runtime
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/event_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class EventTracer {
virtual void log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
const exec_aten::Tensor& output) = 0;
const executorch::aten::Tensor& output) = 0;

/**
* Log an intermediate tensor array output from a delegate.
Expand All @@ -295,7 +295,7 @@ class EventTracer {
virtual void log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
const ArrayRef<exec_aten::Tensor> output) = 0;
const ArrayRef<executorch::aten::Tensor> output) = 0;

/**
* Log an intermediate int output from a delegate.
Expand Down
Loading

0 comments on commit 7d1b0a1

Please sign in to comment.