MLX
 
Loading...
Searching...
No Matches
export_impl.h
Go to the documentation of this file.
1// Copyright © 2024 Apple Inc.
2
3#include "mlx/io/load.h"
4
5#pragma once
6
7namespace mlx::core {
8
9struct FunctionTable;
10
12 void operator()(const std::initializer_list<array>& args) {
13 this->operator()(Args(args));
14 }
15 void operator()(const Args& args);
16 void operator()(const Kwargs& kwargs);
17 void operator()(const Args& args, const Kwargs& kwargs);
18
19 void close();
20
24
25 private:
27 const std::string&,
28 const std::function<std::vector<array>(const Args&)>&,
29 bool shapeless);
30
32 const std::string&,
33 const std::function<std::vector<array>(const Kwargs&)>&,
34 bool shapeless);
35
37 const std::string&,
38 const std::function<std::vector<array>(const Args&, const Kwargs&)>&,
39 bool shapeless);
40
42 const std::string& file,
43 std::function<std::vector<array>(const Args&, const Kwargs&)> fun,
44 bool shapeless);
46 std::function<std::vector<array>(const Args&, const Kwargs& kwargs)> fun;
47 void export_function(const Args& args, const Kwargs& kwargs);
48 std::set<std::uintptr_t> constants;
49 int count{0};
50 bool closed{false};
51 std::shared_ptr<FunctionTable> ftable;
52};
53
54struct ImportedFunction {
55 std::vector<array> operator()(
56 const std::initializer_list<array>& args) const {
57 return this->operator()(Args(args));
58 }
59 std::vector<array> operator()(const Args& args) const;
60 std::vector<array> operator()(const Kwargs& kwargs) const;
61 std::vector<array> operator()(const Args& args, const Kwargs& kwargs) const;
62
63 private:
64 ImportedFunction(const std::string& file);
65 friend ImportedFunction import_function(const std::string&);
66 ImportedFunction();
67
68 std::shared_ptr<FunctionTable> ftable;
69};
70
71} // namespace mlx::core
Definition load.h:109
Definition allocator.h:7
std::vector< array > Args
Definition export.h:11
std::map< std::string, array > Kwargs
Definition export.h:12
void operator()(const Args &args, const Kwargs &kwargs)
friend FunctionExporter exporter(const std::string &, const std::function< std::vector< array >(const Args &)> &, bool shapeless)
Make an exporter to save multiple traces of a given function to the same file.
FunctionExporter & operator=(const FunctionExporter &)=delete
void operator()(const Args &args)
friend FunctionExporter exporter(const std::string &, const std::function< std::vector< array >(const Args &, const Kwargs &)> &, bool shapeless)
FunctionExporter(const FunctionExporter &)=delete
FunctionExporter(FunctionExporter &&other)=default
void operator()(const Kwargs &kwargs)
void operator()(const std::initializer_list< array > &args)
Definition export_impl.h:12
friend FunctionExporter exporter(const std::string &, const std::function< std::vector< array >(const Kwargs &)> &, bool shapeless)
std::vector< array > operator()(const Kwargs &kwargs) const
std::vector< array > operator()(const std::initializer_list< array > &args) const
Definition export_impl.h:55
std::vector< array > operator()(const Args &args) const
friend ImportedFunction import_function(const std::string &)
Import a function from a file.
std::vector< array > operator()(const Args &args, const Kwargs &kwargs) const