| 
 | 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 | +#pragma once  | 
 | 10 | + | 
 | 11 | +#include <executorch/runtime/core/exec_aten/exec_aten.h>  | 
 | 12 | +#include <executorch/runtime/core/freeable_buffer.h>  | 
 | 13 | +#include <executorch/runtime/core/result.h>  | 
 | 14 | +#include <executorch/runtime/core/span.h>  | 
 | 15 | +#include <executorch/runtime/core/tensor_layout.h>  | 
 | 16 | +#include <executorch/runtime/platform/compiler.h>  | 
 | 17 | + | 
 | 18 | +namespace executorch {  | 
 | 19 | +namespace runtime {  | 
 | 20 | + | 
 | 21 | +/**  | 
 | 22 | + * Interface to access and retrieve data via name.  | 
 | 23 | + * See executorch/extension/flat_tensor/ for an example.  | 
 | 24 | + */  | 
 | 25 | +class ET_EXPERIMENTAL NamedDataMap {  | 
 | 26 | + public:  | 
 | 27 | +  virtual ~NamedDataMap() = default;  | 
 | 28 | +  /**  | 
 | 29 | +   * Get tensor metadata by fully qualified name (FQN).  | 
 | 30 | +   *  | 
 | 31 | +   * @param fqn Fully qualified name of the tensor.  | 
 | 32 | +   * @return Result containing TensorLayout with tensor metadata.  | 
 | 33 | +   */  | 
 | 34 | +  ET_NODISCARD virtual Result<const executorch::runtime::TensorLayout>  | 
 | 35 | +  get_metadata(const char* fqn) const = 0;  | 
 | 36 | +  /**  | 
 | 37 | +   * Get tensor data by fully qualified name (FQN).  | 
 | 38 | +   *  | 
 | 39 | +   * @param fqn Fully qualified name of the tensor.  | 
 | 40 | +   * @return Result containing a FreeableBuffer with the tensor data.  | 
 | 41 | +   */  | 
 | 42 | +  ET_NODISCARD virtual Result<FreeableBuffer> get_data(  | 
 | 43 | +      const char* fqn) const = 0;  | 
 | 44 | + | 
 | 45 | +  /**  | 
 | 46 | +   * Loads data corresponding to the fqn into the provided buffer.  | 
 | 47 | +   *  | 
 | 48 | +   * @param fqn Fully qualified name of the tensor.  | 
 | 49 | +   * @param size The number of bytes to load.  | 
 | 50 | +   * @param buffer The buffer to load the data into. Must point to at least  | 
 | 51 | +   * `size` bytes of memory.  | 
 | 52 | +   * @return An error code on if the load was successful.  | 
 | 53 | +   */  | 
 | 54 | +  ET_NODISCARD virtual Error  | 
 | 55 | +  load_data_into(const char* fqn, size_t size, void* buffer) const = 0;  | 
 | 56 | + | 
 | 57 | +  /**  | 
 | 58 | +   * Get the number of keys in the NamedDataMap.  | 
 | 59 | +   *  | 
 | 60 | +   * @return Result containing the number of keys.  | 
 | 61 | +   */  | 
 | 62 | +  ET_NODISCARD virtual Result<int> get_num_keys() const = 0;  | 
 | 63 | + | 
 | 64 | +  /**  | 
 | 65 | +   * Get the key at the given index.  | 
 | 66 | +   *  | 
 | 67 | +   * @param index The index of the key to retrieve.  | 
 | 68 | +   * @return Result containing the key at the given index.  | 
 | 69 | +   */  | 
 | 70 | +  ET_NODISCARD virtual Result<const char*> get_key(int index) const = 0;  | 
 | 71 | +};  | 
 | 72 | + | 
 | 73 | +} // namespace runtime  | 
 | 74 | +} // namespace executorch  | 
0 commit comments