Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 7c6566a

Browse files
authored
[SYCL] Check cache directory settings (#337)
Add tests to check that: - cache is disabled if no environment variables defining cache root directory are set; - cache can be enabled if at least one evironment variable is set.
1 parent c8093ac commit 7c6566a

File tree

4 files changed

+171
-103
lines changed

4 files changed

+171
-103
lines changed

SYCL/KernelAndProgram/cache_env_vars.cpp

Lines changed: 7 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -22,108 +22,12 @@
2222
// CPU OCL JIT 0.12 0.12 0.16 1.1 16
2323
// CPU OCL Cache 0.01 0.01 0.01 0.02 0.08
2424

25-
// CHECK-BUILD: piProgramBuild
26-
// CHECK-BUILD-NOT: piProgramCreateWithBinary
25+
// CHECK-BUILD-NOT: piProgramCreateWithBinary(
26+
// CHECK-BUILD: piProgramCreate(
27+
// CHECK-BUILD: piProgramBuild(
2728

28-
// CHECK-CACHE-NOT: piProgramBuild
29-
// CHECK-CACHE: piProgramCreateWithBinary
29+
// CHECK-CACHE-NOT: piProgramCreate(
30+
// CHECK-CACHE: piProgramCreateWithBinary(
31+
// CHECK-CACHE: piProgramBuild(
3032

31-
#define INC1(x) ((x) = (x) + 1);
32-
33-
#define INC10(x) \
34-
INC1(x) \
35-
INC1(x) \
36-
INC1(x) \
37-
INC1(x) \
38-
INC1(x) \
39-
INC1(x) \
40-
INC1(x) \
41-
INC1(x) \
42-
INC1(x) \
43-
INC1(x)
44-
45-
#define INC100(x) \
46-
INC10(x) \
47-
INC10(x) \
48-
INC10(x) \
49-
INC10(x) \
50-
INC10(x) \
51-
INC10(x) \
52-
INC10(x) \
53-
INC10(x) \
54-
INC10(x) \
55-
INC10(x)
56-
57-
#define INC1000(x) \
58-
INC100(x) \
59-
INC100(x) \
60-
INC100(x) \
61-
INC100(x) \
62-
INC100(x) \
63-
INC100(x) \
64-
INC100(x) \
65-
INC100(x) \
66-
INC100(x) \
67-
INC100(x)
68-
69-
#define INC10000(x) \
70-
INC1000(x) \
71-
INC1000(x) \
72-
INC1000(x) \
73-
INC1000(x) \
74-
INC1000(x) \
75-
INC1000(x) \
76-
INC1000(x) \
77-
INC1000(x) \
78-
INC1000(x) \
79-
INC1000(x)
80-
81-
#define INC100000(x) \
82-
INC10000(x) \
83-
INC10000(x) \
84-
INC10000(x) \
85-
INC10000(x) \
86-
INC10000(x) \
87-
INC10000(x) \
88-
INC10000(x) \
89-
INC10000(x) \
90-
INC10000(x) \
91-
INC10000(x)
92-
93-
#include <CL/sycl.hpp>
94-
#include <chrono>
95-
#include <iostream>
96-
class Inc;
97-
template <class Kernel> void check_build_time(cl::sycl::queue &q) {
98-
cl::sycl::program program(q.get_context());
99-
auto start = std::chrono::steady_clock::now();
100-
program.build_with_kernel_type<Kernel>();
101-
auto end = std::chrono::steady_clock::now();
102-
103-
std::chrono::duration<double> elapsed_seconds = end - start;
104-
std::cout << "elapsed build time: " << elapsed_seconds.count() << "s\n";
105-
}
106-
int main(int argc, char **argv) {
107-
auto start = std::chrono::steady_clock::now();
108-
// Test program and kernel APIs when building a kernel.
109-
{
110-
cl::sycl::queue q;
111-
check_build_time<Inc>(q);
112-
113-
int data = 0;
114-
{
115-
cl::sycl::buffer<int, 1> buf(&data, cl::sycl::range<1>(1));
116-
cl::sycl::range<1> NumOfWorkItems{buf.get_count()};
117-
118-
q.submit([&](cl::sycl::handler &cgh) {
119-
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
120-
cgh.parallel_for<class Inc>(
121-
NumOfWorkItems, [=](cl::sycl::id<1> WIid) { TARGET_IMAGE(acc[0]) });
122-
});
123-
}
124-
// check_build_time<Inc>(q);
125-
auto end = std::chrono::steady_clock::now();
126-
std::chrono::duration<double> elapsed_seconds = end - start;
127-
std::cout << "elapsed kernel time: " << elapsed_seconds.count() << "s\n";
128-
}
129-
}
33+
#include "cache_env_vars.hpp"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS
2+
3+
#define INC1(x) ((x) = (x) + 1);
4+
5+
#define INC10(x) \
6+
INC1(x) \
7+
INC1(x) \
8+
INC1(x) \
9+
INC1(x) \
10+
INC1(x) \
11+
INC1(x) \
12+
INC1(x) \
13+
INC1(x) \
14+
INC1(x) \
15+
INC1(x)
16+
17+
#define INC100(x) \
18+
INC10(x) \
19+
INC10(x) \
20+
INC10(x) \
21+
INC10(x) \
22+
INC10(x) \
23+
INC10(x) \
24+
INC10(x) \
25+
INC10(x) \
26+
INC10(x) \
27+
INC10(x)
28+
29+
#define INC1000(x) \
30+
INC100(x) \
31+
INC100(x) \
32+
INC100(x) \
33+
INC100(x) \
34+
INC100(x) \
35+
INC100(x) \
36+
INC100(x) \
37+
INC100(x) \
38+
INC100(x) \
39+
INC100(x)
40+
41+
#define INC10000(x) \
42+
INC1000(x) \
43+
INC1000(x) \
44+
INC1000(x) \
45+
INC1000(x) \
46+
INC1000(x) \
47+
INC1000(x) \
48+
INC1000(x) \
49+
INC1000(x) \
50+
INC1000(x) \
51+
INC1000(x)
52+
53+
#define INC100000(x) \
54+
INC10000(x) \
55+
INC10000(x) \
56+
INC10000(x) \
57+
INC10000(x) \
58+
INC10000(x) \
59+
INC10000(x) \
60+
INC10000(x) \
61+
INC10000(x) \
62+
INC10000(x) \
63+
INC10000(x)
64+
65+
#include <CL/sycl.hpp>
66+
#include <chrono>
67+
#include <iostream>
68+
class Inc;
69+
template <class Kernel> void check_build_time(cl::sycl::queue &q) {
70+
cl::sycl::program program(q.get_context());
71+
auto start = std::chrono::steady_clock::now();
72+
program.build_with_kernel_type<Kernel>();
73+
auto end = std::chrono::steady_clock::now();
74+
75+
std::chrono::duration<double> elapsed_seconds = end - start;
76+
std::cout << "elapsed build time: " << elapsed_seconds.count() << "s\n";
77+
}
78+
int main(int argc, char **argv) {
79+
auto start = std::chrono::steady_clock::now();
80+
// Test program and kernel APIs when building a kernel.
81+
{
82+
cl::sycl::queue q;
83+
check_build_time<Inc>(q);
84+
85+
int data = 0;
86+
{
87+
cl::sycl::buffer<int, 1> buf(&data, cl::sycl::range<1>(1));
88+
cl::sycl::range<1> NumOfWorkItems{buf.get_count()};
89+
90+
q.submit([&](cl::sycl::handler &cgh) {
91+
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
92+
cgh.parallel_for<class Inc>(
93+
NumOfWorkItems, [=](cl::sycl::id<1> WIid) { TARGET_IMAGE(acc[0]) });
94+
});
95+
}
96+
// check_build_time<Inc>(q);
97+
auto end = std::chrono::steady_clock::now();
98+
std::chrono::duration<double> elapsed_seconds = end - start;
99+
std::cout << "elapsed kernel time: " << elapsed_seconds.count() << "s\n";
100+
}
101+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// No JITing for host devices and diffrent environment variables on linux and
2+
// windows.
3+
// REQUIRES: (level_zero || opencl) && linux
4+
5+
// RUN: rm -rf %t/cache_dir
6+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -DTARGET_IMAGE=INC100
7+
8+
// When no environment variables pointing cache directory are set the cache is
9+
// disabled
10+
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u HOME env -u XDG_CACHE_HOME SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
11+
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u HOME env -u XDG_CACHE_HOME SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
12+
13+
// When any of environment variables pointing to cache root is present cache is
14+
// enabled
15+
// RUN: rm -rf %t/cache_dir
16+
// RUN: env SYCL_CACHE_PERSISTENT=1 XDG_CACHE_HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
17+
// RUN: env SYCL_CACHE_PERSISTENT=1 XDG_CACHE_HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
18+
// RUN: rm -rf %t/cache_dir
19+
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
20+
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u HOME %t.out %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
21+
// RUN: rm -rf %t/cache_dir
22+
// RUN: env SYCL_CACHE_PERSISTENT=1 HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
23+
// RUN: env SYCL_CACHE_PERSISTENT=1 HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
24+
25+
// CHECK-BUILD-NOT: piProgramCreateWithBinary(
26+
// CHECK-BUILD: piProgramCreate(
27+
// CHECK-BUILD: piProgramBuild(
28+
29+
// CHECK-CACHE-NOT: piProgramCreate(
30+
// CHECK-CACHE: piProgramCreateWithBinary(
31+
// CHECK-CACHE: piProgramBuild(
32+
33+
#include "cache_env_vars.hpp"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// No JITing for host devices and diffrent environment variables on linux and
2+
// windows.
3+
// REQUIRES: (level_zero || opencl) && windows
4+
5+
// RUN: rm -rf %t/cache_dir
6+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -DTARGET_IMAGE=INC100
7+
8+
// When no environment variables pointing cache directory are set the cache is
9+
// disabled
10+
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u AppData SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
11+
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u AppData SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
12+
13+
// When any of environment variables pointing to cache root is present cache is
14+
// enabled
15+
// RUN: rm -rf %t/cache_dir
16+
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u AppData %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
17+
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u AppData %t.out %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
18+
// RUN: rm -rf %t/cache_dir
19+
// RUN: env SYCL_CACHE_PERSISTENT=1 AppData=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
20+
// RUN: env SYCL_CACHE_PERSISTENT=1 AppData=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
21+
22+
// CHECK-BUILD-NOT: piProgramCreateWithBinary(
23+
// CHECK-BUILD: piProgramCreate(
24+
// CHECK-BUILD: piProgramBuild(
25+
26+
// CHECK-CACHE-NOT: piProgramCreate(
27+
// CHECK-CACHE: piProgramCreateWithBinary(
28+
// CHECK-CACHE: piProgramBuild(
29+
30+
#include "cache_env_vars.hpp"

0 commit comments

Comments
 (0)