prepared_tensor_cache.h#

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace core
namespace runtime

Typedefs

using PreparedSourceLoader = std::function<std::vector<uint8_t>()>#
using PreparedTensorPrepacker = std::function<std::vector<uint8_t>(const std::vector<uint8_t>&)>#
using PreparedTensorPublisher = std::function<void(const std::vector<uint8_t>&)>#

Enums

enum class PreparedCacheMissReason#

Values:

enumerator kNone#
enumerator kNotFound#
enumerator kCorrupt#
enumerator kStaleSource#
enumerator kWrongArchitecture#
enumerator kWrongIsa#
enumerator kWrongRuntime#
enumerator kWrongLayout#
enumerator kWrongFormat#
class PreparedTensorCache#
#include <prepared_tensor_cache.h>

Loads compatible prepared tensors before their portable source and persists misses.

Public Functions

PreparedTensorCache() = default#
~PreparedTensorCache()#
PreparedTensorCache(const PreparedTensorCache&) = delete#
PreparedTensorCache &operator=(const PreparedTensorCache&) = delete#
PreparedTensorLoadResult LoadOrPrepare(const std::filesystem::path &cache_path, const PreparedTensorMetadata &required_metadata, const PreparedSourceLoader &load_source, const PreparedTensorPrepacker &prepack, const PreparedTensorPublisher &publish)#

Publishes a compatible cached payload or prepares the portable source on a miss.

Cache persistence starts only after the complete prepared value is published.

void WaitForBackgroundWrites()#

Waits for all pending atomic cache writes.

std::vector<std::string> TakePersistenceDiagnostics()#

Waits for pending writes and returns their diagnostics.

Private Functions

void PersistInBackground(std::filesystem::path cache_path, PreparedTensorMetadata metadata, std::vector<uint8_t> payload)#
void WriterLoop()#

Private Members

std::mutex mutex_#
std::condition_variable writer_ready_#
std::deque<PersistenceRequest> pending_#
std::thread writer_#
size_t pending_writes_ = 0#
bool stop_writer_ = false#
std::vector<std::string> persistence_diagnostics_#
struct PersistenceRequest#

Public Members

std::filesystem::path cache_path#
PreparedTensorMetadata metadata#
std::vector<uint8_t> payload#
struct PreparedTensorLoadResult#
#include <prepared_tensor_cache.h>

Public Members

bool cache_hit = false#
PreparedCacheMissReason miss_reason = PreparedCacheMissReason::kNone#
std::string diagnostic#
struct PreparedTensorMetadata#
#include <prepared_tensor_cache.h>

Public Members

std::string source_digest#
std::string architecture#
platform::CpuFeatureSet required_isa#
std::string runtime#
std::string runtime_version#
std::string kernel_layout#
std::string format_version#