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 | |
20 | /*! |
21 | * \file param_dict.cc |
22 | * \brief Implementation and registration of parameter dictionary |
23 | * serializing/deserializing functions. |
24 | */ |
25 | #include "param_dict.h" |
26 | |
27 | #include <dmlc/memory_io.h> |
28 | #include <tvm/runtime/registry.h> |
29 | |
30 | #include <string> |
31 | #include <utility> |
32 | #include <vector> |
33 | |
34 | #include "../../runtime/file_utils.h" |
35 | |
36 | namespace tvm { |
37 | namespace relay { |
38 | |
39 | using namespace runtime; |
40 | |
41 | TVM_REGISTER_GLOBAL("tvm.relay._save_param_dict" ) |
42 | .set_body_typed([](const Map<String, NDArray>& params) { |
43 | std::string s = ::tvm::runtime::SaveParams(params); |
44 | // copy return array so it is owned by the ret value |
45 | TVMRetValue rv; |
46 | rv = TVMByteArray{s.data(), s.size()}; |
47 | return rv; |
48 | }); |
49 | TVM_REGISTER_GLOBAL("tvm.relay._load_param_dict" ).set_body_typed([](const String& s) { |
50 | return ::tvm::runtime::LoadParams(s); |
51 | }); |
52 | |
53 | } // namespace relay |
54 | } // namespace tvm |
55 | |