file_util.h 2.03 KB
Newer Older
1
/**
Minjie Wang's avatar
Minjie Wang committed
2
 *  Copyright (c) 2017 by Contributors
3
4
 * @file file_util.h
 * @brief Minimum file manipulation util for runtime.
Minjie Wang's avatar
Minjie Wang committed
5
 */
6
7
#ifndef DGL_RUNTIME_FILE_UTIL_H_
#define DGL_RUNTIME_FILE_UTIL_H_
Minjie Wang's avatar
Minjie Wang committed
8
9

#include <string>
10
#include <unordered_map>
11

Minjie Wang's avatar
Minjie Wang committed
12
13
#include "meta_data.h"

14
namespace dgl {
Minjie Wang's avatar
Minjie Wang committed
15
namespace runtime {
16
/**
17
18
19
 * @brief Get file format from given file name or format argument.
 * @param file_name The name of the file.
 * @param format The format of the file.
Minjie Wang's avatar
Minjie Wang committed
20
 */
21
22
std::string GetFileFormat(
    const std::string& file_name, const std::string& format);
Minjie Wang's avatar
Minjie Wang committed
23

24
/**
25
 * @return the directory in which DGL stores cached files.
26
 *         May be set using DGL_CACHE_DIR; defaults to system locations.
Minjie Wang's avatar
Minjie Wang committed
27
28
29
 */
std::string GetCacheDir();

30
/**
31
32
 * @brief Get meta file path given file name and format.
 * @param file_name The name of the file.
Minjie Wang's avatar
Minjie Wang committed
33
34
35
 */
std::string GetMetaFilePath(const std::string& file_name);

36
/**
37
38
39
 * @brief Get file basename (i.e. without leading directories)
 * @param file_name The name of the file.
 * @return the base name
Minjie Wang's avatar
Minjie Wang committed
40
41
42
 */
std::string GetFileBasename(const std::string& file_name);

43
/**
44
45
46
 * @brief Load binary file into a in-memory buffer.
 * @param file_name The name of the file.
 * @param data The data to be loaded.
Minjie Wang's avatar
Minjie Wang committed
47
 */
48
void LoadBinaryFromFile(const std::string& file_name, std::string* data);
Minjie Wang's avatar
Minjie Wang committed
49

50
/**
51
52
53
 * @brief Load binary file into a in-memory buffer.
 * @param file_name The name of the file.
 * @param data The binary data to be saved.
Minjie Wang's avatar
Minjie Wang committed
54
 */
55
void SaveBinaryToFile(const std::string& file_name, const std::string& data);
Minjie Wang's avatar
Minjie Wang committed
56

57
/**
58
59
60
 * @brief Save meta data to file.
 * @param file_name The name of the file.
 * @param fmap The function info map.
Minjie Wang's avatar
Minjie Wang committed
61
62
63
64
65
 */
void SaveMetaDataToFile(
    const std::string& file_name,
    const std::unordered_map<std::string, FunctionInfo>& fmap);

66
/**
67
68
69
 * @brief Load meta data to file.
 * @param file_name The name of the file.
 * @param fmap The function info map.
Minjie Wang's avatar
Minjie Wang committed
70
71
72
73
74
 */
void LoadMetaDataFromFile(
    const std::string& file_name,
    std::unordered_map<std::string, FunctionInfo>* fmap);
}  // namespace runtime
75
}  // namespace dgl
76
#endif  // DGL_RUNTIME_FILE_UTIL_H_