Skip to content

Commit 02d8a29

Browse files
committed
[Comgr][Cache] Disable the cache by default
1 parent c0f84ba commit 02d8a29

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

amd/comgr/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,15 @@ and eviction policy can be manipulated through specific environment variables.
120120
If an issue arises during cache initialization, the execution will proceed with
121121
the cache turned off.
122122

123+
By default, the cache is turned off, set the environment variable
124+
`AMD_COMGR_CACHE=1` to enable it. This may change in a future release.
125+
126+
* `AMD_COMGR_CACHE`: When unset or set to 0, the cache is turned off.
123127
* `AMD_COMGR_CACHE_DIR`: When set to "", the cache is turned off. If assigned a
124128
value, that value is used as the path for cache storage. By default, it is
125129
directed to "$XDG_CACHE_HOME/comgr_cache" (which defaults to
126130
"$USER/.cache/comgr_cache" on Linux, and "%LOCALAPPDATA%\cache\comgr_cache"
127-
on Windows).
131+
on Microsoft Windows).
128132
* `AMD_COMGR_CACHE_POLICY`: If assigned a value, the string is interpreted and
129133
applied to the cache pruning policy. The cache is pruned only upon program
130134
termination. The string format aligns with [Clang's ThinLTO cache pruning policy](https://clang.llvm.org/docs/ThinLTO.html#cache-pruning).

amd/comgr/src/comgr-env.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ StringRef getCachePolicy() {
8181
}
8282

8383
StringRef getCacheDirectory() {
84+
// By default the cache is deactivated. We hope to remove this variable in the
85+
// future.
86+
static const char *Enable = std::getenv("AMD_COMGR_CACHE");
87+
bool CacheDisabled = !Enable || StringRef(Enable) == "0";
88+
if (CacheDisabled)
89+
return "";
90+
8491
static const char *EnvCacheDirectory = std::getenv("AMD_COMGR_CACHE_DIR");
8592
if (EnvCacheDirectory)
8693
return EnvCacheDirectory;

amd/comgr/test-lit/compile-minimal-test-cached-bad-dir.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: export AMD_COMGR_CACHE=1
2+
//
13
// COM: fail to create the cache, but still produce something valid
24
// RUN: rm -f %t.log
35
// RUN: echo "not a directory" > %t.txt

amd/comgr/test-lit/compile-minimal-test-cached-bad-policy.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: export AMD_COMGR_CACHE=1
2+
//
13
// COM: fail to create the cache, but still produce something valid
24
// RUN: rm -f %t_log
35
// RUN: AMD_COMGR_CACHE_DIR=%t.cache \
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
// RUN: rm -fr %t.cache
22
//
3+
// RUN: unset AMD_COMGR_CACHE
4+
// RUN: AMD_COMGR_CACHE_DIR=%t.cache compile-minimal-test %S/compile-minimal-test.cl %t.bin
5+
// RUN: llvm-objdump -d %t.bin | FileCheck %S/compile-minimal-test.cl
6+
// RUN: [ ! -d %t.cache ]
7+
//
8+
// RUN: export AMD_COMGR_CACHE=0
9+
// RUN: AMD_COMGR_CACHE_DIR=%t.cache compile-minimal-test %S/compile-minimal-test.cl %t.bin
10+
// RUN: llvm-objdump -d %t.bin | FileCheck %S/compile-minimal-test.cl
11+
// RUN: [ ! -d %t.cache ]
12+
//
13+
// RUN: export AMD_COMGR_CACHE=1
14+
//
315
// COM: run once and check that the cache directory exists and it has more than 1 element (one for the cache tag, one or more for the cached commands)
416
// RUN: AMD_COMGR_CACHE_DIR=%t.cache compile-minimal-test %S/compile-minimal-test.cl %t_a.bin
5-
// RUN: llvm-objdump -d %t_a.bin | FileCheck %S/compile-minimal-test.cl
17+
// RUN: llvm-objdump -d %t_a.bin | FileCheck %S/compile-minimal-test.cl
618
// RUN: COUNT_BEFORE=$(ls "%t.cache" | wc -l)
719
// COM: One element for the tag, one for bc->obj another for obj->exec. No elements for src->bc since we currently not support it.
820
// RUN: [ 3 -eq $COUNT_BEFORE ]
@@ -11,3 +23,4 @@
1123
// RUN: llvm-objdump -d %t_b.bin | FileCheck %S/compile-minimal-test.cl
1224
// RUN: COUNT_AFTER=$(ls "%t.cache" | wc -l)
1325
// RUN: [ $COUNT_AFTER = $COUNT_BEFORE ]
26+
//

0 commit comments

Comments
 (0)