File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
extension/apple/ExecuTorch/Exported Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -134,4 +134,28 @@ __attribute__((deprecated("This API is experimental.")))
134134
135135@end
136136
137+ #pragma mark - BytesNoCopy Category
138+
139+ @interface ExecuTorchTensor (BytesNoCopy)
140+
141+ /* *
142+ * Initializes a tensor without copying the provided data.
143+ *
144+ * @param pointer A pointer to the data buffer.
145+ * @param shape An NSArray of NSNumber objects representing the tensor's shape.
146+ * @param strides An NSArray of NSNumber objects representing the tensor's strides.
147+ * @param dimensionOrder An NSArray of NSNumber objects indicating the order of dimensions.
148+ * @param dataType An ExecuTorchDataType value specifying the element type.
149+ * @param shapeDynamism An ExecuTorchShapeDynamism value indicating whether the shape is static or dynamic.
150+ * @return An initialized ExecuTorchTensor instance using the provided data buffer.
151+ */
152+ - (instancetype )initWithBytesNoCopy : (void *)pointer
153+ shape : (NSArray <NSNumber *> *)shape
154+ strides : (NSArray <NSNumber *> *)strides
155+ dimensionOrder : (NSArray <NSNumber *> *)dimensionOrder
156+ dataType : (ExecuTorchDataType)dataType
157+ shapeDynamism : (ExecuTorchShapeDynamism)shapeDynamism ;
158+
159+ @end
160+
137161NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change 1313
1414#import < executorch/extension/tensor/tensor.h>
1515
16+ using namespace executorch ::aten;
1617using namespace executorch ::extension;
1718
1819@implementation ExecuTorchTensor {
@@ -69,3 +70,25 @@ - (NSInteger)count {
6970}
7071
7172@end
73+
74+ @implementation ExecuTorchTensor (BytesNoCopy)
75+
76+ - (instancetype )initWithBytesNoCopy : (void *)pointer
77+ shape : (NSArray <NSNumber *> *)shape
78+ strides : (NSArray <NSNumber *> *)strides
79+ dimensionOrder : (NSArray <NSNumber *> *)dimensionOrder
80+ dataType : (ExecuTorchDataType)dataType
81+ shapeDynamism : (ExecuTorchShapeDynamism)shapeDynamism {
82+ ET_CHECK (pointer);
83+ auto tensor = make_tensor_ptr (
84+ utils::toVector<SizesType>(shape),
85+ pointer,
86+ utils::toVector<DimOrderType>(dimensionOrder),
87+ utils::toVector<StridesType>(strides),
88+ static_cast <ScalarType>(dataType),
89+ static_cast <TensorShapeDynamism>(shapeDynamism)
90+ );
91+ return [self initWithNativeInstance: &tensor];
92+ }
93+
94+ @end
You can’t perform that action at this time.
0 commit comments