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>
25#include <tvm/runtime/tensor.h>
26
27#include <string>
28#include <unordered_map>
29#include <vector>
30
31namespace tvm {
32namespace runtime {
33namespace vm {
34
40 struct FileRecord {
42 struct ParamRecord {
51 Device device, const std::string* raw_data,
52 ffi::Optional<ffi::Tensor>* staging_buffer = nullptr) const;
53
55 std::string name;
57 ffi::Shape shape;
59 DLDataType dtype;
61 std::string format;
63 int64_t nbytes;
65 int64_t byte_offset;
66 };
67
69 TVM_RUNTIME_EXTRA_DLL ffi::Array<ffi::Tensor> Load(
70 Device device, //
71 const std::string& path_prefix, //
72 std::string* raw_data_buffer, //
73 ffi::Optional<ffi::Tensor>* staging_buffer = nullptr) const;
74
76 std::string data_path;
78 std::string format;
80 int64_t nbytes;
82 std::vector<ParamRecord> records;
83 };
85 std::vector<FileRecord> records;
87 std::string path;
88
92 TVM_RUNTIME_EXTRA_DLL static TensorCacheMetadata LoadFromStr(const std::string& json_str,
93 const std::string& path);
94};
95
96} // namespace vm
97} // namespace runtime
98} // namespace tvm
99
100#endif // TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
Device-independent tensor allocation, copies, views and serialization.
Parent runtime-extra symbol visibility.
#define TVM_RUNTIME_EXTRA_DLL
Definition extra_base.h:45
Definition builtin.h:29
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
DLDevice Device
Definition device_api.h:46
Metadata of each parameter.
Definition tensor_cache_support.h:42
std::string name
Name of the parameter.
Definition tensor_cache_support.h:55
DLDataType dtype
Data type of the parameter.
Definition tensor_cache_support.h:59
int64_t byte_offset
Offset from the raw stream.
Definition tensor_cache_support.h:65
std::string format
Format of the parameter.
Definition tensor_cache_support.h:61
ffi::Shape shape
Shape of the parameter.
Definition tensor_cache_support.h:57
int64_t nbytes
Number of bytes.
Definition tensor_cache_support.h:63
TVM_RUNTIME_EXTRA_DLL ffi::Tensor Load(Device device, const std::string *raw_data, ffi::Optional< ffi::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:40
TVM_RUNTIME_EXTRA_DLL ffi::Array< ffi::Tensor > Load(Device device, const std::string &path_prefix, std::string *raw_data_buffer, ffi::Optional< ffi::Tensor > *staging_buffer=nullptr) const
Load a FileRecord into memory.
std::vector< ParamRecord > records
The parameters in the file.
Definition tensor_cache_support.h:82
std::string data_path
Relative path to the bin file.
Definition tensor_cache_support.h:76
std::string format
Format of the file.
Definition tensor_cache_support.h:78
int64_t nbytes
Size of the file.
Definition tensor_cache_support.h:80
Metadata for Tensor cache, which by default, is named as "tensor-cache.json".
Definition tensor_cache_support.h:38
static TVM_RUNTIME_EXTRA_DLL TensorCacheMetadata LoadFromStr(const std::string &json_str, const std::string &path)
Load the metadata from a given JSON string.
static TVM_RUNTIME_EXTRA_DLL TensorCacheMetadata Load(const std::string &path)
Load the metadata from a specific directory.
std::string path
The path to the tensor-cache.json file.
Definition tensor_cache_support.h:87
std::vector< FileRecord > records
The files in the Tensor cache.
Definition tensor_cache_support.h:85