Skip to content

Commit

Permalink
ocl: revised ACC_OPENCL_CACHE
Browse files Browse the repository at this point in the history
- Handle legacy-NEO and redirect NEO_CACHE_DIR to temporary folder.
- Introduced ACC_OPENCL_TEMPDIR.
- Updated LIBXSMM (Daint-CI).
  • Loading branch information
hfp committed Nov 13, 2023
1 parent 3da6e53 commit cf41a08
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/ocl.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if [ ! -d "${HOME}/libxsmm" ]; then
fi
cd "${HOME}/libxsmm"
git fetch
git checkout 54b8bb32042d204ff6fe550fa70d961f22c0b99e
git checkout ab992663b97571c9306ac01f6ca9a4a76bb5b559
make -j
cd ..

Expand Down
44 changes: 35 additions & 9 deletions src/acc/opencl/acc_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# define S_ISDIR(A) ((S_IFMT & (A)) == S_IFDIR)
# endif

# if !defined(ACC_OPENCL_TEMPDIR) && 1
# define ACC_OPENCL_TEMPDIR "/tmp"
# endif
# if !defined(ACC_OPENCL_CACHEDIR) && 1
# define ACC_OPENCL_CACHEDIR ".cl_cache"
# endif
Expand Down Expand Up @@ -273,20 +276,43 @@ int c_dbcsr_acc_init(void) {
# endif
# if defined(ACC_OPENCL_CACHEDIR)
{
const char* const env_cache = getenv("ACC_OPENCL_CACHE");
const int cache = (NULL == env_cache ? CL_FALSE : (0 != atoi(env_cache) ? CL_TRUE : CL_FALSE));
const char *const env_cache = getenv("ACC_OPENCL_CACHE"), *env_cachedir = getenv("NEO_CACHE_DIR");
int cache = (NULL == env_cache ? 0 : atoi(env_cache));
struct stat cachedir;
if (0 != cache || (stat(ACC_OPENCL_CACHEDIR, &cachedir) == 0 && S_ISDIR(cachedir.st_mode))) {
# if !defined(_WIN32)
static char cl_cache_dir[] = "cl_cache_dir=" ACC_OPENCL_CACHEDIR;
if (0 == cache) {
if (stat(ACC_OPENCL_CACHEDIR, &cachedir) == 0 && S_ISDIR(cachedir.st_mode)) cache = 1;
else if (stat(ACC_OPENCL_TEMPDIR "/" ACC_OPENCL_CACHEDIR, &cachedir) == 0 && S_ISDIR(cachedir.st_mode)) cache = 2;
}
if (1 == cache) {
static char neo_cachedir[] = "NEO_CACHE_DIR=" ACC_OPENCL_CACHEDIR;
static char ocl_cachedir[] = "cl_cache_dir=" ACC_OPENCL_CACHEDIR;
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(neo_cachedir)); /* putenv before entering OpenCL */
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(ocl_cachedir)); /* putenv before entering OpenCL */
env_cachedir = ACC_OPENCL_CACHEDIR;
}
# if defined(ACC_OPENCL_TEMPDIR)
else if (NULL == env_cachedir) { /* code-path entered by default */
if (NULL == env_cache || 0 != cache) { /* customize NEO_CACHE_DIR unless ACC_OPENCL_CACHE=0 */
static char neo_cachedir[] = "NEO_CACHE_DIR=" ACC_OPENCL_TEMPDIR "/" ACC_OPENCL_CACHEDIR;
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(neo_cachedir)); /* putenv before entering OpenCL */
env_cachedir = ACC_OPENCL_TEMPDIR "/" ACC_OPENCL_CACHEDIR;
}
if (0 != cache) { /* legacy-NEO is treated with explicit opt-in */
static char ocl_cachedir[] = "cl_cache_dir=" ACC_OPENCL_TEMPDIR "/" ACC_OPENCL_CACHEDIR;
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(ocl_cachedir)); /* putenv before entering OpenCL */
}
}
# endif
if (NULL != env_cachedir) {
# if defined(_WIN32)
LIBXSMM_UNUSED(env_cachedir);
# else
# if defined(S_IRWXU) && defined(S_IRGRP) && defined(S_IXGRP) && defined(S_IROTH) && defined(S_IXOTH)
const int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
# else
const int mode = 0xFFFFFFFF;
# endif
if (0 == mkdir(ACC_OPENCL_CACHEDIR, mode) || EEXIST == errno) { /* putenv before entering OpenCL */
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(cl_cache_dir)); /* soft-error */
}
ACC_OPENCL_EXPECT(0 == mkdir(env_cachedir, mode) || EEXIST == errno); /* soft-error */
# endif
}
}
Expand Down Expand Up @@ -1254,7 +1280,7 @@ int c_dbcsr_acc_opencl_kernel(int source_is_file, const char source[], const cha
/* consider preprocessing kernel for analysis (cpp); failure does not matter (result) */
# if defined(ACC_OPENCL_CPPBIN)
if (0 != c_dbcsr_acc_opencl_config.dump && NULL == file_src) {
nchar = LIBXSMM_SNPRINTF(buffer_name, sizeof(buffer_name), "/tmp/.%s.XXXXXX", kernel_name);
nchar = LIBXSMM_SNPRINTF(buffer_name, sizeof(buffer_name), ACC_OPENCL_TEMPDIR "/.%s.XXXXXX", kernel_name);
if (0 < nchar && (int)sizeof(buffer_name) > nchar) {
FILE* const file_cpp = fopen(ACC_OPENCL_CPPBIN, "rb");
const char* sed_pattern = "";
Expand Down

0 comments on commit cf41a08

Please sign in to comment.