|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <executorch/backends/aoti/common_shims_slim.h> |
| 10 | + |
| 11 | +namespace executorch { |
| 12 | +namespace backends { |
| 13 | +namespace aoti { |
| 14 | + |
| 15 | +extern "C" { |
| 16 | + |
| 17 | +// ============================================================ |
| 18 | +// Basic Property Getters - Implementations |
| 19 | +// ============================================================ |
| 20 | + |
| 21 | +AOTITorchError aoti_torch_get_data_ptr(Tensor* tensor, void** ret_data_ptr) { |
| 22 | + if (tensor == nullptr || ret_data_ptr == nullptr) { |
| 23 | + return Error::InvalidArgument; |
| 24 | + } |
| 25 | + *ret_data_ptr = tensor->data_ptr(); |
| 26 | + return Error::Ok; |
| 27 | +} |
| 28 | + |
| 29 | +AOTITorchError aoti_torch_get_sizes(Tensor* tensor, int64_t** ret_sizes) { |
| 30 | + if (tensor == nullptr || ret_sizes == nullptr) { |
| 31 | + return Error::InvalidArgument; |
| 32 | + } |
| 33 | + *ret_sizes = const_cast<int64_t*>(tensor->sizes().data()); |
| 34 | + return Error::Ok; |
| 35 | +} |
| 36 | + |
| 37 | +AOTITorchError aoti_torch_get_strides(Tensor* tensor, int64_t** ret_strides) { |
| 38 | + if (tensor == nullptr || ret_strides == nullptr) { |
| 39 | + return Error::InvalidArgument; |
| 40 | + } |
| 41 | + *ret_strides = const_cast<int64_t*>(tensor->strides().data()); |
| 42 | + return Error::Ok; |
| 43 | +} |
| 44 | + |
| 45 | +AOTITorchError aoti_torch_get_dtype(Tensor* tensor, int32_t* ret_dtype) { |
| 46 | + if (tensor == nullptr || ret_dtype == nullptr) { |
| 47 | + return Error::InvalidArgument; |
| 48 | + } |
| 49 | + *ret_dtype = static_cast<int32_t>(tensor->dtype()); |
| 50 | + return Error::Ok; |
| 51 | +} |
| 52 | + |
| 53 | +AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim) { |
| 54 | + if (tensor == nullptr || ret_dim == nullptr) { |
| 55 | + return Error::InvalidArgument; |
| 56 | + } |
| 57 | + *ret_dim = static_cast<int64_t>(tensor->dim()); |
| 58 | + return Error::Ok; |
| 59 | +} |
| 60 | + |
| 61 | +int32_t aoti_torch_layout_strided() { |
| 62 | + // Slimtensor only support strided layout, the return value will always be 0, |
| 63 | + // a.k.a at::Layout::Strided; |
| 64 | + return 0; |
| 65 | +} |
| 66 | + |
| 67 | +} // extern "C" |
| 68 | + |
| 69 | +} // namespace aoti |
| 70 | +} // namespace backends |
| 71 | +} // namespace executorch |
0 commit comments