executorch-sys 0.13.0

Unsafe Rust bindings for ExecuTorch - On-device AI across mobile, embedded and edge for PyTorch
Documentation
#pragma once

#include "executorch_rs/c_bridge.h"

#include <cstddef>
#include <cstdint>
#include "executorch/runtime/core/exec_aten/exec_aten.h"

#include "executorch/extension/memory_allocator/malloc_memory_allocator.h"

#include "executorch/extension/module/module.h"
#if defined(EXECUTORCH_RS_MODULE)
#include "executorch-sys/src/cxx_bridge/module.rs.h"
#endif

#if defined(EXECUTORCH_RS_TENSOR_PTR)
#include "executorch-sys/src/cxx_bridge/tensor_ptr.rs.h"
#include <vector>
#endif

namespace executorch_rs
{
#if defined(EXECUTORCH_RS_STD)
    std::unique_ptr<executorch::extension::MallocMemoryAllocator> MallocMemoryAllocator_new();
    struct ET_MemoryAllocator *MallocMemoryAllocator_as_memory_allocator(executorch::extension::MallocMemoryAllocator &self);
    std::unique_ptr<struct ET_MemoryAllocator> MallocMemoryAllocator_into_memory_allocator_unique_ptr(std::unique_ptr<executorch::extension::MallocMemoryAllocator> self);

    std::unique_ptr<struct ET_MemoryAllocator> BufferMemoryAllocator_into_memory_allocator_unique_ptr(struct ET_MemoryAllocator &self);
#endif

#if defined(EXECUTORCH_RS_TENSOR_PTR)
    std::shared_ptr<executorch::aten::Tensor> TensorPtr_new(
        std::unique_ptr<std::vector<int32_t>> sizes,
        uint8_t *data,
        std::unique_ptr<std::vector<uint8_t>> dim_order,
        std::unique_ptr<std::vector<int32_t>> strides,
        ET_ScalarType scalar_type,
        struct ET_Device device,
        ET_TensorShapeDynamism dynamism,
        rust::Box<executorch_rs::cxx_util::RustAny> allocation);
    std::shared_ptr<executorch::aten::Tensor> TensorPtr_clone(
        const executorch::aten::Tensor &tensor,
        ET_ScalarType scalar_type);
    std::shared_ptr<executorch::aten::Tensor> TensorPtr_clone_to(
        std::shared_ptr<executorch::aten::Tensor> tensor,
        struct ET_Device device);
#endif

#if defined(EXECUTORCH_RS_MODULE)
    std::unique_ptr<executorch::extension::Module> Module_new(
        const std::string &file_path,
        rust::Slice<const rust::Str> data_files,
        const ET_ModuleLoadMode load_mode,
        std::unique_ptr<executorch::runtime::EventTracer> event_tracer,
        std::unique_ptr<struct ET_MemoryAllocator> memory_allocator,
        std::unique_ptr<struct ET_MemoryAllocator> temp_allocator,
        bool share_memory_arenas);

    ET_Error Module_load(executorch::extension::Module &self, const struct ET_LoadBackendOptionsMap *backend_options, ET_ProgramVerification verification);
    const struct ET_LoadBackendOptionsMap &Module_backend_options(const executorch::extension::Module &self);
    bool Module_is_loaded(const executorch::extension::Module &self);
    ET_Error Module_num_methods(executorch::extension::Module &self, size_t *method_num_out);
    ET_Error Module_method_names(executorch::extension::Module &self, rust::Vec<rust::String> *method_names_out);
    ET_Error Module_load_method(executorch::extension::Module &self, const std::string &method_name, ET_HierarchicalAllocator *planned_memory, executorch::runtime::EventTracer *event_tracer);
    bool Module_unload_method(executorch::extension::Module &self, const std::string &method_name);
    bool Module_is_method_loaded(const executorch::extension::Module &self, const std::string &method_name);
    ET_Error Module_method_meta(executorch::extension::Module &self, const std::string &method_name, ET_MethodMeta *method_meta_out);
    ET_Error Module_execute(executorch::extension::Module &self, const std::string &method_name, ET_ArrayRefEValue inputs, ET_VecEValue *outputs);
#endif
}