2024-12-25 03:19:13 +08:00
|
|
|
// Copyright © 2024 Apple Inc.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <set>
|
2025-04-21 22:17:22 +08:00
|
|
|
#include <unordered_map>
|
2024-12-25 03:19:13 +08:00
|
|
|
#include "mlx/array.h"
|
|
|
|
|
|
|
|
namespace mlx::core {
|
|
|
|
|
|
|
|
using Args = std::vector<array>;
|
2025-04-21 22:17:22 +08:00
|
|
|
using Kwargs = std::unordered_map<std::string, array>;
|
2024-12-25 03:19:13 +08:00
|
|
|
|
|
|
|
struct FunctionExporter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an exporter to save multiple traces of a given function to
|
|
|
|
* the same file.
|
|
|
|
*/
|
|
|
|
FunctionExporter exporter(
|
|
|
|
const std::string& file,
|
|
|
|
const std::function<std::vector<array>(const Args&)>& fun,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
FunctionExporter exporter(
|
|
|
|
const std::string& file,
|
|
|
|
const std::function<std::vector<array>(const Kwargs&)>& fun,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
FunctionExporter exporter(
|
|
|
|
const std::string& path,
|
|
|
|
const std::function<std::vector<array>(const Args&, const Kwargs&)>& fun,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export a function to a file.
|
|
|
|
*/
|
|
|
|
void export_function(
|
|
|
|
const std::string& file,
|
|
|
|
const std::function<std::vector<array>(const Args&)>& fun,
|
|
|
|
const Args& args,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
void export_function(
|
|
|
|
const std::string& file,
|
|
|
|
const std::function<std::vector<array>(const Kwargs&)>& fun,
|
|
|
|
const Kwargs& kwargs,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
void export_function(
|
|
|
|
const std::string& file,
|
|
|
|
const std::function<std::vector<array>(const Args&, const Kwargs&)>& fun,
|
|
|
|
const Args& args,
|
|
|
|
const Kwargs& kwargs,
|
|
|
|
bool shapeless = false);
|
|
|
|
|
|
|
|
struct ImportedFunction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import a function from a file.
|
|
|
|
*/
|
|
|
|
ImportedFunction import_function(const std::string& file);
|
|
|
|
|
|
|
|
} // namespace mlx::core
|
|
|
|
|
|
|
|
#include "mlx/export_impl.h"
|