File tree Expand file tree Collapse file tree 5 files changed +57
-6
lines changed Expand file tree Collapse file tree 5 files changed +57
-6
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,22 @@ These include:
125
125
certain runtime headers. If this is not set, it has a default value of
126
126
"${ROCM_PATH}/llvm".
127
127
128
+ Comgr utilizes a cache to preserve the results of compilations between executions.
129
+ The cache's status (enabled/disabled), storage location for its results,
130
+ and eviction policy can be manipulated through specific environment variables.
131
+ If an issue arises during cache initialization, the execution will proceed with
132
+ the cache turned off.
133
+
134
+ * ` AMD_COMGR_CACHE_DIR ` : When set to "", the cache is turned off. If assigned a
135
+ value, that value is used as the path for cache storage. By default, it is
136
+ directed to "$XDG_CACHE_HOME/comgr_cache" (which defaults to
137
+ "$USER/.cache/comgr_cache" on Linux, and "%LOCALAPPDATA%\cache\comgr_cache"
138
+ on Windows).
139
+ * ` AMD_COMGR_CACHE_POLICY ` : If assigned a value, the string is interpreted and
140
+ applied to the cache pruning policy. The cache is pruned only upon program
141
+ termination. The string format aligns with [ Clang's ThinLTO cache pruning policy] ( https://clang.llvm.org/docs/ThinLTO.html#cache-pruning ) .
142
+ The default policy is set as: "prune_interval=1h: prune_expiration =0h: cache_size =75%: cache_size_bytes =30g: cache_size_files =0".
143
+
128
144
Comgr also supports some environment variables to aid in debugging. These
129
145
include:
130
146
Original file line number Diff line number Diff line change 37
37
#include " llvm/ADT/Twine.h"
38
38
#include " llvm/Support/VirtualFileSystem.h"
39
39
40
- #include < fstream>
41
- #include < memory>
42
- #include < stdlib.h>
43
-
44
40
using namespace llvm ;
45
41
46
42
namespace COMGR {
@@ -278,5 +274,28 @@ StringRef getHIPPath() { return getDetector()->getHIPPath(); }
278
274
279
275
StringRef getLLVMPath () { return getDetector ()->getLLVMPath (); }
280
276
277
+ StringRef getCachePolicy () {
278
+ static const char *EnvCachePolicy = std::getenv (" AMD_COMGR_CACHE_POLICY" );
279
+ return EnvCachePolicy;
280
+ }
281
+
282
+ StringRef getCacheDirectory () {
283
+ static const char *EnvCacheDirectory = std::getenv (" AMD_COMGR_CACHE_DIR" );
284
+ if (EnvCacheDirectory)
285
+ return EnvCacheDirectory;
286
+
287
+ // mark Result as static to keep it cached across calls
288
+ static SmallString<256 > Result;
289
+ if (!Result.empty ())
290
+ return Result;
291
+
292
+ if (sys::path::cache_directory (Result)) {
293
+ sys::path::append (Result, Twine (" comgr_cache" ));
294
+ return Result;
295
+ }
296
+
297
+ return " " ;
298
+ }
299
+
281
300
} // namespace env
282
301
} // namespace COMGR
Original file line number Diff line number Diff line change @@ -66,6 +66,15 @@ llvm::StringRef getHIPPath();
66
66
// / otherwise return the default LLVM path.
67
67
llvm::StringRef getLLVMPath ();
68
68
69
+ // / If environment variable AMD_COMGR_CACHE_POLICY is set, return the
70
+ // / environment variable, otherwise return empty
71
+ llvm::StringRef getCachePolicy ();
72
+
73
+ // / If environment variable AMD_COMGR_CACHE_DIR is set, return the environment
74
+ // / variable, otherwise return the default path: On Linux it's typically
75
+ // / $HOME/.cache/comgr_cache (depends on XDG_CACHE_HOME)
76
+ llvm::StringRef getCacheDirectory ();
77
+
69
78
} // namespace env
70
79
} // namespace COMGR
71
80
Original file line number Diff line number Diff line change 14
14
15
15
if not config .comgr_disable_spirv :
16
16
config .available_features .add ("comgr-has-spirv" )
17
+
18
+ # By default, disable the cache for the tests.
19
+ # Test for the cache must explicitly enable this variable.
20
+ config .environment ['AMD_COMGR_CACHE_DIR' ] = ""
Original file line number Diff line number Diff line change @@ -193,9 +193,12 @@ endif()
193
193
add_dependencies (check-comgr ${name} )
194
194
# Windows binaries have no equivalent to RPATH, so we must set their PATH to
195
195
# include the .lib/.dll directory.
196
- if (NOT ( UNIX ) )
196
+ if (UNIX )
197
197
set_tests_properties (${test_name}
198
- PROPERTIES ENVIRONMENT "PATH=$<TARGET_LINKER_FILE_DIR:amd_comgr>" )
198
+ PROPERTIES ENVIRONMENT "AMD_COMGR_CACHE_DIR=;" )
199
+ else ()
200
+ set_tests_properties (${test_name}
201
+ PROPERTIES ENVIRONMENT "PATH=$<TARGET_LINKER_FILE_DIR:amd_comgr>;AMD_COMGR_CACHE_DIR=;" )
199
202
endif ()
200
203
endmacro ()
201
204
You can’t perform that action at this time.
0 commit comments