20
20
#include " paddle/fluid/framework/phi_utils.h"
21
21
#include " paddle/fluid/framework/var_desc.h"
22
22
23
+ #include " paddle/pir/include/core/attribute.h"
24
+ #include " paddle/pir/include/core/builtin_attribute.h"
25
+ COMMON_DECLARE_bool (enable_pir_api);
23
26
namespace paddle ::jit::utils {
24
27
25
28
bool IsPersistable (framework::VarDesc* desc_ptr) {
@@ -33,6 +36,15 @@ bool IsPersistable(framework::VarDesc* desc_ptr) {
33
36
return desc_ptr->Persistable ();
34
37
}
35
38
39
+ bool IsPersistable (pir::Value* value_ptr) {
40
+ auto is_persistable =
41
+ value_ptr->attribute <pir::BoolAttribute>(kAttrIsPersistable );
42
+ if (is_persistable && is_persistable.data ()) {
43
+ return true ;
44
+ }
45
+ return false ;
46
+ }
47
+
36
48
bool StartsWith (const std::string& str, const std::string& prefix) {
37
49
return str.compare (0 , prefix.length (), prefix) == 0 ;
38
50
}
@@ -62,9 +74,9 @@ bool FileExists(const std::string& file_path) {
62
74
return file.good ();
63
75
}
64
76
65
- const std::vector<std::pair<std::string, std::string>> PdmodelFilePaths (
77
+ const std::vector<std::pair<std::string, std::string>> ModelFilePaths (
66
78
const std::string& path) {
67
- std::vector<std::pair<std::string, std::string>> pdmodel_paths ;
79
+ std::vector<std::pair<std::string, std::string>> model_paths ;
68
80
std::string format_path = path;
69
81
ReplaceAll (&format_path, R"( \\)" , " /" );
70
82
ReplaceAll (&format_path, R"( \)" , " /" );
@@ -80,27 +92,46 @@ const std::vector<std::pair<std::string, std::string>> PdmodelFilePaths(
80
92
struct dirent * ptr = nullptr ;
81
93
82
94
while ((ptr = readdir (dir)) != nullptr ) {
95
+ std::string prefix = " " ;
83
96
std::string file_name = ptr->d_name ;
84
-
85
- if (StartsWith (file_name, layer_name) &&
86
- EndsWith (file_name, PDMODEL_SUFFIX)) {
87
- std::string prefix = file_name.substr (
88
- 0 , file_name.length () - std::string (PDMODEL_SUFFIX).length ());
89
-
90
- if (prefix == layer_name) {
91
- pdmodel_paths.emplace_back (
92
- std::make_pair (" forward" , dir_path + file_name));
93
- } else {
94
- std::string func_name = prefix.substr (layer_name.size () + 1 );
95
- pdmodel_paths.emplace_back (
96
- std::make_pair (func_name, dir_path + file_name));
97
+ if (FLAGS_enable_pir_api) {
98
+ if (StartsWith (file_name, layer_name) &&
99
+ EndsWith (file_name, JSON_SUFFIX)) {
100
+ std::string prefix = file_name.substr (
101
+ 0 , file_name.length () - std::string (JSON_SUFFIX).length ());
102
+
103
+ if (prefix == layer_name) {
104
+ model_paths.emplace_back (
105
+ std::make_pair (" forward" , dir_path + file_name));
106
+ } else {
107
+ std::string func_name = prefix.substr (layer_name.size () + 1 );
108
+ model_paths.emplace_back (
109
+ std::make_pair (func_name, dir_path + file_name));
110
+ }
111
+ VLOG (3 ) << " func_name: " << model_paths.back ().first
112
+ << " , path:" << dir_path + file_name;
113
+ }
114
+ } else {
115
+ if (StartsWith (file_name, layer_name) &&
116
+ EndsWith (file_name, PDMODEL_SUFFIX)) {
117
+ std::string prefix = file_name.substr (
118
+ 0 , file_name.length () - std::string (PDMODEL_SUFFIX).length ());
119
+
120
+ if (prefix == layer_name) {
121
+ model_paths.emplace_back (
122
+ std::make_pair (" forward" , dir_path + file_name));
123
+ } else {
124
+ std::string func_name = prefix.substr (layer_name.size () + 1 );
125
+ model_paths.emplace_back (
126
+ std::make_pair (func_name, dir_path + file_name));
127
+ }
128
+ VLOG (3 ) << " func_name: " << model_paths.back ().first
129
+ << " , path:" << dir_path + file_name;
97
130
}
98
- VLOG (3 ) << " func_name: " << pdmodel_paths.back ().first
99
- << " , path:" << dir_path + file_name;
100
131
}
101
132
}
102
133
closedir (dir);
103
- return pdmodel_paths ;
134
+ return model_paths ;
104
135
}
105
136
106
137
void InitKernelSignatureMap () {
0 commit comments