executorch 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.executorch-version +1 -0
- data/CHANGELOG.md +24 -38
- data/README.md +143 -129
- data/ext/executorch/core/core.cpp +1131 -0
- data/ext/executorch/core/dtype.hpp +157 -0
- data/ext/executorch/core/module_core.hpp +165 -0
- data/ext/executorch/core/status.hpp +100 -0
- data/ext/executorch/core/tensor_core.hpp +73 -0
- data/ext/executorch/executorch.map +6 -0
- data/ext/executorch/extconf.rb +254 -173
- data/ext/executorch/rb_errors.cpp +117 -0
- data/ext/executorch/rb_executorch.cpp +69 -0
- data/ext/executorch/rb_internal.hpp +121 -0
- data/ext/executorch/rb_module.cpp +760 -0
- data/ext/executorch/rb_tensor.cpp +1281 -0
- data/lib/executorch/method_meta.rb +70 -0
- data/lib/executorch/module.rb +56 -0
- data/lib/executorch/sdk.rb +251 -0
- data/lib/executorch/tensor.rb +85 -0
- data/lib/executorch/version.rb +3 -1
- data/lib/executorch.rb +8 -204
- metadata +26 -23
- data/ext/executorch/executorch.cpp +0 -582
- data/ext/executorch/utils.h +0 -140
data/ext/executorch/utils.h
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
#ifndef EXECUTORCH_RUBY_UTILS_H
|
|
2
|
-
#define EXECUTORCH_RUBY_UTILS_H
|
|
3
|
-
|
|
4
|
-
#include <rice/rice.hpp>
|
|
5
|
-
#include <rice/stl.hpp>
|
|
6
|
-
#include <executorch/runtime/core/error.h>
|
|
7
|
-
#include <executorch/runtime/core/result.h>
|
|
8
|
-
|
|
9
|
-
// Error handling macros - translate C++ exceptions to Ruby exceptions
|
|
10
|
-
#define HANDLE_ET_ERRORS try {
|
|
11
|
-
|
|
12
|
-
#define END_HANDLE_ET_ERRORS \
|
|
13
|
-
} \
|
|
14
|
-
catch (const Rice::Exception &ex) { \
|
|
15
|
-
throw; \
|
|
16
|
-
} \
|
|
17
|
-
catch (const std::exception &ex) { \
|
|
18
|
-
rb_raise(rb_eRuntimeError, "ExecuTorch error: %s", ex.what()); \
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
namespace executorch_ruby {
|
|
22
|
-
|
|
23
|
-
inline void check_error(executorch::runtime::Error error) {
|
|
24
|
-
if (error != executorch::runtime::Error::Ok) {
|
|
25
|
-
const char* error_name = "Unknown error";
|
|
26
|
-
switch (error) {
|
|
27
|
-
case executorch::runtime::Error::Ok:
|
|
28
|
-
return;
|
|
29
|
-
case executorch::runtime::Error::Internal:
|
|
30
|
-
error_name = "Internal error";
|
|
31
|
-
break;
|
|
32
|
-
case executorch::runtime::Error::InvalidState:
|
|
33
|
-
error_name = "Invalid state";
|
|
34
|
-
break;
|
|
35
|
-
case executorch::runtime::Error::InvalidArgument:
|
|
36
|
-
error_name = "Invalid argument";
|
|
37
|
-
break;
|
|
38
|
-
case executorch::runtime::Error::InvalidType:
|
|
39
|
-
error_name = "Invalid type";
|
|
40
|
-
break;
|
|
41
|
-
case executorch::runtime::Error::NotFound:
|
|
42
|
-
error_name = "Not found";
|
|
43
|
-
break;
|
|
44
|
-
case executorch::runtime::Error::MemoryAllocationFailed:
|
|
45
|
-
error_name = "Memory allocation failed";
|
|
46
|
-
break;
|
|
47
|
-
case executorch::runtime::Error::AccessFailed:
|
|
48
|
-
error_name = "Access failed";
|
|
49
|
-
break;
|
|
50
|
-
case executorch::runtime::Error::NotSupported:
|
|
51
|
-
error_name = "Not supported";
|
|
52
|
-
break;
|
|
53
|
-
case executorch::runtime::Error::DelegateInvalidCompatibility:
|
|
54
|
-
error_name = "Delegate invalid compatibility";
|
|
55
|
-
break;
|
|
56
|
-
case executorch::runtime::Error::DelegateMemoryAllocationFailed:
|
|
57
|
-
error_name = "Delegate memory allocation failed";
|
|
58
|
-
break;
|
|
59
|
-
case executorch::runtime::Error::DelegateInvalidHandle:
|
|
60
|
-
error_name = "Delegate invalid handle";
|
|
61
|
-
break;
|
|
62
|
-
default:
|
|
63
|
-
error_name = "Unknown error";
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
rb_raise(rb_eRuntimeError, "ExecuTorch error: %s", error_name);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Helper to unwrap Result<T> and raise Ruby exception on error
|
|
71
|
-
template <typename T>
|
|
72
|
-
T unwrap_result(executorch::runtime::Result<T>&& result) {
|
|
73
|
-
if (!result.ok()) {
|
|
74
|
-
check_error(result.error());
|
|
75
|
-
// Should never reach here, but just in case
|
|
76
|
-
rb_raise(rb_eRuntimeError, "ExecuTorch: unexpected error");
|
|
77
|
-
}
|
|
78
|
-
return std::move(result.get());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Convert ExecuTorch ScalarType to Ruby symbol
|
|
82
|
-
// Uses short names (:int, :long, :float) to match input symbols
|
|
83
|
-
inline VALUE scalar_type_to_symbol(executorch::aten::ScalarType dtype) {
|
|
84
|
-
switch (dtype) {
|
|
85
|
-
case executorch::aten::ScalarType::Byte:
|
|
86
|
-
return ID2SYM(rb_intern("byte"));
|
|
87
|
-
case executorch::aten::ScalarType::Char:
|
|
88
|
-
return ID2SYM(rb_intern("char"));
|
|
89
|
-
case executorch::aten::ScalarType::Short:
|
|
90
|
-
return ID2SYM(rb_intern("short"));
|
|
91
|
-
case executorch::aten::ScalarType::Int:
|
|
92
|
-
return ID2SYM(rb_intern("int"));
|
|
93
|
-
case executorch::aten::ScalarType::Long:
|
|
94
|
-
return ID2SYM(rb_intern("long"));
|
|
95
|
-
case executorch::aten::ScalarType::Half:
|
|
96
|
-
return ID2SYM(rb_intern("half"));
|
|
97
|
-
case executorch::aten::ScalarType::Float:
|
|
98
|
-
return ID2SYM(rb_intern("float"));
|
|
99
|
-
case executorch::aten::ScalarType::Double:
|
|
100
|
-
return ID2SYM(rb_intern("double"));
|
|
101
|
-
case executorch::aten::ScalarType::Bool:
|
|
102
|
-
return ID2SYM(rb_intern("bool"));
|
|
103
|
-
default:
|
|
104
|
-
return ID2SYM(rb_intern("unknown"));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
inline executorch::aten::ScalarType symbol_to_scalar_type(VALUE sym) {
|
|
109
|
-
if (!RB_TYPE_P(sym, T_SYMBOL)) {
|
|
110
|
-
rb_raise(rb_eTypeError, "Expected Symbol for dtype");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
ID id = SYM2ID(sym);
|
|
114
|
-
|
|
115
|
-
if (id == rb_intern("uint8") || id == rb_intern("byte")) {
|
|
116
|
-
return executorch::aten::ScalarType::Byte;
|
|
117
|
-
} else if (id == rb_intern("int8") || id == rb_intern("char")) {
|
|
118
|
-
return executorch::aten::ScalarType::Char;
|
|
119
|
-
} else if (id == rb_intern("int16") || id == rb_intern("short")) {
|
|
120
|
-
return executorch::aten::ScalarType::Short;
|
|
121
|
-
} else if (id == rb_intern("int32") || id == rb_intern("int")) {
|
|
122
|
-
return executorch::aten::ScalarType::Int;
|
|
123
|
-
} else if (id == rb_intern("int64") || id == rb_intern("long")) {
|
|
124
|
-
return executorch::aten::ScalarType::Long;
|
|
125
|
-
} else if (id == rb_intern("float16") || id == rb_intern("half")) {
|
|
126
|
-
return executorch::aten::ScalarType::Half;
|
|
127
|
-
} else if (id == rb_intern("float32") || id == rb_intern("float")) {
|
|
128
|
-
return executorch::aten::ScalarType::Float;
|
|
129
|
-
} else if (id == rb_intern("float64") || id == rb_intern("double")) {
|
|
130
|
-
return executorch::aten::ScalarType::Double;
|
|
131
|
-
} else if (id == rb_intern("bool")) {
|
|
132
|
-
return executorch::aten::ScalarType::Bool;
|
|
133
|
-
} else {
|
|
134
|
-
rb_raise(rb_eArgError, "Unknown dtype: %s", rb_id2name(id));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
} // namespace executorch_ruby
|
|
139
|
-
|
|
140
|
-
#endif // EXECUTORCH_RUBY_UTILS_H
|