Skip to content

Commit 9200253

Browse files
committed
[slim tensor migration 2/n] update slimtensor namespace
This stack aims to migrate slim tensor into ExecuTorch stack to make it as internal tensor representation of cudabackend. This diff updates namespaces of slimtensor files to executorch standard. More specific: 1. namespace standalone::slim → namespace executorch::backends::aoti::slim 2. namespace standalone::c10 → namespace executorch::backends::aoti::slim::c10 3. Added torch::executor::SlimTensor backward-compatible alias Differential Revision: [D89442123](https://our.internmc.facebook.com/intern/diff/D89442123/) ghstack-source-id: 330172608 Pull Request resolved: #16313
1 parent dea4fbc commit 9200253

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1547
-1206
lines changed

backends/aoti/slim/c10/core/Contiguity.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <algorithm>
77
#include <cstdint>
88

9-
namespace standalone::c10 {
9+
namespace executorch::backends::aoti::slim::c10 {
1010

1111
template <typename T>
1212
bool _compute_contiguous(ArrayRef<T> sizes, ArrayRef<T> strides, T numel) {
@@ -148,4 +148,4 @@ bool _compute_non_overlapping_and_dense(
148148
return true;
149149
}
150150

151-
} // namespace standalone::c10
151+
} // namespace executorch::backends::aoti::slim::c10

backends/aoti/slim/c10/core/Device.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// Copied from c10/core/DeviceType.h with some modifications
1919

20-
namespace standalone::c10 {
20+
namespace executorch::backends::aoti::slim::c10 {
2121
namespace detail {
2222
enum class DeviceStringParsingState {
2323
kSTART,
@@ -341,18 +341,21 @@ inline std::ostream& operator<<(std::ostream& stream, const Device& device) {
341341
stream << device.str();
342342
return stream;
343343
}
344-
} // namespace standalone::c10
344+
} // namespace executorch::backends::aoti::slim::c10
345345

346346
namespace std {
347347
template <>
348-
struct hash<standalone::c10::Device> {
349-
size_t operator()(standalone::c10::Device d) const noexcept {
348+
struct hash<executorch::backends::aoti::slim::c10::Device> {
349+
size_t operator()(
350+
executorch::backends::aoti::slim::c10::Device d) const noexcept {
350351
// Are you here because this static assert failed? Make sure you ensure
351352
// that the bitmasking code below is updated accordingly!
352353
static_assert(
353-
sizeof(standalone::c10::DeviceType) == 1, "DeviceType is not 8-bit");
354+
sizeof(executorch::backends::aoti::slim::c10::DeviceType) == 1,
355+
"DeviceType is not 8-bit");
354356
static_assert(
355-
sizeof(standalone::c10::DeviceIndex) == 1, "DeviceIndex is not 8-bit");
357+
sizeof(executorch::backends::aoti::slim::c10::DeviceIndex) == 1,
358+
"DeviceIndex is not 8-bit");
356359
// Note [Hazard when concatenating signed integers]
357360
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
358361
// We must first convert to a same-sized unsigned type, before promoting to

backends/aoti/slim/c10/core/DeviceType.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <executorch/backends/aoti/slim/c10/util/Exception.h>
1717

18-
namespace standalone::c10 {
18+
namespace executorch::backends::aoti::slim::c10 {
1919
enum class DeviceType : int8_t {
2020
CPU = 0,
2121
CUDA = 1, // CUDA.
@@ -122,12 +122,13 @@ inline std::ostream& operator<<(std::ostream& stream, DeviceType type) {
122122
stream << DeviceTypeName(type, /* lower case */ true);
123123
return stream;
124124
}
125-
} // namespace standalone::c10
125+
} // namespace executorch::backends::aoti::slim::c10
126126

127127
namespace std {
128128
template <>
129-
struct hash<standalone::c10::DeviceType> {
130-
std::size_t operator()(standalone::c10::DeviceType k) const {
129+
struct hash<executorch::backends::aoti::slim::c10::DeviceType> {
130+
std::size_t operator()(
131+
executorch::backends::aoti::slim::c10::DeviceType k) const {
131132
return std::hash<int>()(static_cast<int>(k));
132133
}
133134
};

backends/aoti/slim/c10/core/Layout.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <cstdint>
66
#include <ostream>
77

8-
namespace standalone::c10 {
8+
namespace executorch::backends::aoti::slim::c10 {
99
enum class Layout : int8_t {
1010
Strided,
1111
Sparse,
@@ -50,4 +50,4 @@ inline std::ostream& operator<<(std::ostream& stream, c10::Layout layout) {
5050
}
5151
}
5252

53-
} // namespace standalone::c10
53+
} // namespace executorch::backends::aoti::slim::c10

backends/aoti/slim/c10/core/MemoryFormat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Regardless of input tensors format, the output should be in channels_last
2626
// format.
2727

28-
namespace standalone::c10 {
28+
namespace executorch::backends::aoti::slim::c10 {
2929
enum class MemoryFormat : int8_t {
3030
Contiguous,
3131
Preserve,
@@ -38,7 +38,7 @@ enum class MemoryFormat : int8_t {
3838
// the memory format could be preserved, and it was switched to old default
3939
// behaviour of contiguous
4040
#define LEGACY_CONTIGUOUS_MEMORY_FORMAT \
41-
::standalone::c10::get_contiguous_memory_format()
41+
::executorch::backends::aoti::slim::c10::get_contiguous_memory_format()
4242

4343
inline MemoryFormat get_contiguous_memory_format() {
4444
return MemoryFormat::Contiguous;
@@ -288,4 +288,4 @@ inline bool is_channels_last_strides_3d(
288288
return is_channels_last_strides_3d<int64_t>(sizes, strides);
289289
}
290290

291-
} // namespace standalone::c10
291+
} // namespace executorch::backends::aoti::slim::c10

backends/aoti/slim/c10/core/Scalar.h

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// Copy-pasted from c10/core/Scalar.h, but dropping SymScalar support
1717

18-
namespace standalone::c10 {
18+
namespace executorch::backends::aoti::slim::c10 {
1919

2020
/**
2121
* Scalar represents a 0-dimensional tensor which contains a single element.
@@ -86,22 +86,23 @@ class Scalar {
8686
v.i = convert<int64_t, bool>(vv);
8787
}
8888

89-
#define DEFINE_ACCESSOR(type, name) \
90-
type to##name() const { \
91-
if (Tag::HAS_d == tag) { \
92-
return checked_convert<type, double>(v.d, #type); \
93-
} else if (Tag::HAS_z == tag) { \
94-
return checked_convert<type, standalone::c10::complex<double>>( \
95-
v.z, #type); \
96-
} \
97-
if (Tag::HAS_b == tag) { \
98-
return checked_convert<type, bool>(v.i, #type); \
99-
} else if (Tag::HAS_i == tag) { \
100-
return checked_convert<type, int64_t>(v.i, #type); \
101-
} else if (Tag::HAS_u == tag) { \
102-
return checked_convert<type, uint64_t>(v.u, #type); \
103-
} \
104-
STANDALONE_CHECK(false) \
89+
#define DEFINE_ACCESSOR(type, name) \
90+
type to##name() const { \
91+
if (Tag::HAS_d == tag) { \
92+
return checked_convert<type, double>(v.d, #type); \
93+
} else if (Tag::HAS_z == tag) { \
94+
return checked_convert< \
95+
type, \
96+
executorch::backends::aoti::slim::c10::complex<double>>(v.z, #type); \
97+
} \
98+
if (Tag::HAS_b == tag) { \
99+
return checked_convert<type, bool>(v.i, #type); \
100+
} else if (Tag::HAS_i == tag) { \
101+
return checked_convert<type, int64_t>(v.i, #type); \
102+
} else if (Tag::HAS_u == tag) { \
103+
return checked_convert<type, uint64_t>(v.u, #type); \
104+
} \
105+
STANDALONE_CHECK(false) \
105106
}
106107

107108
// TODO: Support ComplexHalf accessor
@@ -193,8 +194,9 @@ class Scalar {
193194

194195
template <
195196
typename T,
196-
typename std::enable_if_t<!standalone::c10::is_complex<T>::value, int> =
197-
0>
197+
typename std::enable_if_t<
198+
!executorch::backends::aoti::slim::c10::is_complex<T>::value,
199+
int> = 0>
198200
bool equal(T num) const {
199201
if (isComplex()) {
200202
auto val = v.z;
@@ -223,7 +225,9 @@ class Scalar {
223225

224226
template <
225227
typename T,
226-
typename std::enable_if_t<standalone::c10::is_complex<T>::value, int> = 0>
228+
typename std::enable_if_t<
229+
executorch::backends::aoti::slim::c10::is_complex<T>::value,
230+
int> = 0>
227231
bool equal(T num) const {
228232
if (isComplex()) {
229233
return v.z == num;
@@ -257,20 +261,20 @@ class Scalar {
257261
}
258262
}
259263

260-
standalone::c10::ScalarType type() const {
264+
executorch::backends::aoti::slim::c10::ScalarType type() const {
261265
if (isComplex()) {
262-
return standalone::c10::ScalarType::ComplexDouble;
266+
return executorch::backends::aoti::slim::c10::ScalarType::ComplexDouble;
263267
} else if (isFloatingPoint()) {
264-
return standalone::c10::ScalarType::Double;
268+
return executorch::backends::aoti::slim::c10::ScalarType::Double;
265269
} else if (isIntegral(/*includeBool=*/false)) {
266270
// Represent all integers as long, UNLESS it is unsigned and therefore
267271
// unrepresentable as long
268272
if (Tag::HAS_u == tag) {
269-
return standalone::c10::ScalarType::UInt64;
273+
return executorch::backends::aoti::slim::c10::ScalarType::UInt64;
270274
}
271-
return standalone::c10::ScalarType::Long;
275+
return executorch::backends::aoti::slim::c10::ScalarType::Long;
272276
} else if (isBoolean()) {
273-
return standalone::c10::ScalarType::Bool;
277+
return executorch::backends::aoti::slim::c10::ScalarType::Bool;
274278
} else {
275279
throw std::runtime_error("Unknown scalar type.");
276280
}
@@ -313,7 +317,7 @@ class Scalar {
313317
int64_t i;
314318
// See Note [Meaning of HAS_u]
315319
uint64_t u;
316-
standalone::c10::complex<double> z;
320+
executorch::backends::aoti::slim::c10::complex<double> z;
317321
// NOLINTNEXTLINE(modernize-use-equals-default)
318322
v_t() {} // default constructor
319323
} v;
@@ -330,16 +334,18 @@ class Scalar {
330334
template <
331335
typename T,
332336
typename std::enable_if_t<
333-
!std::is_integral_v<T> && !standalone::c10::is_complex<T>::value,
337+
!std::is_integral_v<T> &&
338+
!executorch::backends::aoti::slim::c10::is_complex<T>::value,
334339
bool>* = nullptr>
335340
Scalar(T vv, bool) : tag(Tag::HAS_d) {
336341
v.d = convert<decltype(v.d), T>(vv);
337342
}
338343

339344
template <
340345
typename T,
341-
typename std::enable_if_t<standalone::c10::is_complex<T>::value, bool>* =
342-
nullptr>
346+
typename std::enable_if_t<
347+
executorch::backends::aoti::slim::c10::is_complex<T>::value,
348+
bool>* = nullptr>
343349
Scalar(T vv, bool) : tag(Tag::HAS_z) {
344350
v.z = convert<decltype(v.z), T>(vv);
345351
}
@@ -357,4 +363,4 @@ DEFINE_TO(uint32_t, UInt32)
357363
DEFINE_TO(uint64_t, UInt64)
358364
#undef DEFINE_TO
359365

360-
} // namespace standalone::c10
366+
} // namespace executorch::backends::aoti::slim::c10

0 commit comments

Comments
 (0)