tvm
Loading...
Searching...
No Matches
tensor_cache_support.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19#ifndef TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
20#define TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
21
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/function.h>
24#include <tvm/runtime/tensor.h>
25
26#include <string>
27#include <unordered_map>
28#include <vector>
29
30namespace tvm {
31namespace runtime {
32namespace vm {
33
39 struct FileRecord {
41 struct ParamRecord {
49 TVM_RUNTIME_DLL Tensor Load(Device device, const std::string* raw_data,
50 ffi::Optional<Tensor>* staging_buffer = nullptr) const;
51
53 std::string name;
55 ffi::Shape shape;
59 std::string format;
64 };
65
67 TVM_RUNTIME_DLL ffi::Array<Tensor> Load(Device device, //
68 const std::string& path_prefix, //
69 std::string* raw_data_buffer, //
70 ffi::Optional<Tensor>* staging_buffer = nullptr) const;
71
73 std::string data_path;
75 std::string format;
79 std::vector<ParamRecord> records;
80 };
82 std::vector<FileRecord> records;
84 std::string path;
85
87 TVM_RUNTIME_DLL static TensorCacheMetadata Load(const std::string& path);
90 const std::string& path);
91};
92
93} // namespace vm
94} // namespace runtime
95} // namespace tvm
96
97#endif // TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Managed Tensor. The array is backed by reference counted blocks.
Definition tensor.h:49
Definition builtin.h:29
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
#define TVM_RUNTIME_DLL
Definition base.h:92
A device-independent managed Tensor abstraction.
Metadata of each parameter.
Definition tensor_cache_support.h:41
std::string name
Name of the parameter.
Definition tensor_cache_support.h:53
DLDataType dtype
Data type of the parameter.
Definition tensor_cache_support.h:57
int64_t byte_offset
Offset from the raw stream.
Definition tensor_cache_support.h:63
std::string format
Format of the parameter.
Definition tensor_cache_support.h:59
ffi::Shape shape
Shape of the parameter.
Definition tensor_cache_support.h:55
int64_t nbytes
Number of bytes.
Definition tensor_cache_support.h:61
TVM_RUNTIME_DLL Tensor Load(Device device, const std::string *raw_data, ffi::Optional< Tensor > *staging_buffer=nullptr) const
Load the parameter from raw data.
Each shard of Tensor cache, which by default, is named as "params_shard_x.bin".
Definition tensor_cache_support.h:39
std::vector< ParamRecord > records
The parameters in the file.
Definition tensor_cache_support.h:79
std::string data_path
Relative path to the bin file.
Definition tensor_cache_support.h:73
std::string format
Format of the file.
Definition tensor_cache_support.h:75
int64_t nbytes
Size of the file.
Definition tensor_cache_support.h:77
TVM_RUNTIME_DLL ffi::Array< Tensor > Load(Device device, const std::string &path_prefix, std::string *raw_data_buffer, ffi::Optional< Tensor > *staging_buffer=nullptr) const
Load a FileRecord into memory.
Metadata for Tensor cache, which by default, is named as "tensor-cache.json".
Definition tensor_cache_support.h:37
std::string path
The path to the tensor-cache.json file.
Definition tensor_cache_support.h:84
static TVM_RUNTIME_DLL TensorCacheMetadata Load(const std::string &path)
Load the metadata from a specific directory.
std::vector< FileRecord > records
The files in the Tensor cache.
Definition tensor_cache_support.h:82
static TVM_RUNTIME_DLL TensorCacheMetadata LoadFromStr(const std::string &json_str, const std::string &path)
Load the metadata from a given JSON string.