|
| 1 | +// Tests eviction for in-memory program cache. |
| 2 | + |
| 3 | +// Future optimizations in device code reduction can cause this test to fail. |
| 4 | +// Therefore, adding O0. |
| 5 | +// RUN: %{build} %O0 -o %t.out |
| 6 | + |
| 7 | +// RUN: env SYCL_CACHE_TRACE=2 SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD=20000 %{run} %t.out 2> %t.trace3 |
| 8 | +// RUN: FileCheck %s --input-file=%t.trace3 --check-prefix=CHECK-CACHE-TRACE |
| 9 | + |
| 10 | +#include <sycl/detail/core.hpp> |
| 11 | + |
| 12 | +#include <sycl/specialization_id.hpp> |
| 13 | +#include <sycl/usm.hpp> |
| 14 | + |
| 15 | +using namespace sycl; |
| 16 | + |
| 17 | +constexpr specialization_id<int> spec_id; |
| 18 | + |
| 19 | +int main() { |
| 20 | + queue q; |
| 21 | + |
| 22 | + // The first time the kernel is used, it will be stored in kernel and fast |
| 23 | + // kernel cache. Then next two times it will be fetched from fast kernel |
| 24 | + // cache. |
| 25 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY1:.*]]]: Program inserted. |
| 26 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY1]]]: Program added to the end of eviction list. |
| 27 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 0][Key:{Name = [[KERNELNAME1:.*]]]: Kernel inserted. |
| 28 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 1][Key:{Name = [[KERNELNAME1:.*]]]: Kernel inserted. |
| 29 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 1][Key:{Name = [[KERNELNAME1:.*]]]: Kernel fetched. |
| 30 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 1][Key:{Name = [[KERNELNAME1:.*]]]: Kernel fetched. |
| 31 | + for (int i = 0; i < 3; i++) |
| 32 | + q.single_task([] {}).wait(); |
| 33 | + |
| 34 | + auto *p = malloc_device<int>(1, q); |
| 35 | + |
| 36 | + // Added program and kernel for first loop iteration. |
| 37 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY2:.*]]]: Program inserted. |
| 38 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY2]]]: Program added to the end of eviction list. |
| 39 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 0][Key:{Name = [[KERNELNAME2:.*]]]: Kernel inserted. |
| 40 | + |
| 41 | + // Added program and kernel for second loop iteration. |
| 42 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY3:.*]]]: Program inserted. |
| 43 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY3]]]: Program added to the end of eviction list. |
| 44 | + |
| 45 | + // Eviction triggered. The first program will be evicted from cache. |
| 46 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 0][Key:{Name = [[KERNELNAME1]]]: Kernel evicted. |
| 47 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 1][Key:{Name = [[KERNELNAME1]]]: Kernel evicted. |
| 48 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Program Cache][Key:[[KEY1]]]: Program evicted. |
| 49 | + |
| 50 | + // Kernel for second loop iteration will be inserted into kernel cache. |
| 51 | + // CHECK-CACHE-TRACE: [In-Memory Cache][Thread Id:{{.*}}][Kernel Cache][IsFastCache: 0][Key:{Name = [[KERNELNAME3:.*]]]: Kernel inserted. |
| 52 | + |
| 53 | + for (int i = 0; i < 2; ++i) |
| 54 | + q.submit([&](handler &cgh) { |
| 55 | + cgh.set_specialization_constant<spec_id>(i); |
| 56 | + cgh.parallel_for(1, [=](auto, kernel_handler kh) { |
| 57 | + *p = kh.get_specialization_constant<spec_id>(); |
| 58 | + }); |
| 59 | + }).wait(); |
| 60 | + |
| 61 | + free(p, q); |
| 62 | +} |
0 commit comments