|
1 | | -.. _caching: |
2 | 1 | .. include:: ./../ext_links.txt |
3 | 2 |
|
4 | | - |
5 | | -Caching Mechanism in Numba-dpex |
6 | | -================================ |
| 3 | +Caching Mechanism in ``numba-dpex`` |
| 4 | +=================================== |
7 | 5 |
|
8 | 6 | Caching is done by saving the compiled kernel code, the ELF object of the |
9 | 7 | executable code. By using the kernel code, cached kernels have minimal overhead |
10 | 8 | because no compilation is needed. |
11 | 9 |
|
12 | | -Unlike Numba, we do not perform file-based caching, instead we use a |
13 | | -Least Recently Used (LRU) caching mechanism. However when a kernel needs to be |
14 | | -evicted, we utilize numba's file-based caching mechanism described |
15 | | -`here <https://numba.pydata.org/numba-doc/latest/developer/caching.html>`_. |
| 10 | +Unlike Numba*, ``numba-dpex`` does not perform an exclusive file-based caching, |
| 11 | +instead a Least Recently Used (LRU) caching mechanism is used. However, when a |
| 12 | +kernel needs to be evicted, Numba's file-based caching mechanism is invoked as |
| 13 | +described `here |
| 14 | +<https://numba.pydata.org/numba-doc/latest/developer/caching.html>`_. |
16 | 15 |
|
17 | 16 | Algorithm |
18 | | ---------- |
19 | | - |
20 | | -The caching mechanism for Numba-dpex works as follows: The cache is an LRU cache |
21 | | -backed by an ordered dictionary mapped onto a doubly linked list. The tail of |
22 | | -the list contains the most recently used (MRU) kernel and the head of the list |
23 | | -contains the least recently used (LRU) kernel. The list has a fixed size. If a |
24 | | -new kernel arrives to be cached and if the size is already on the maximum limit, |
25 | | -the algorithm evicts the LRU kernel to make room for the MRU kernel. The evicted |
26 | | -item will be serialized and pickled into a file using Numba's caching mechanism. |
27 | | - |
28 | | -Everytime whenever a kernel needs to be retrieved from the cache, the mechanism |
29 | | -will look for the kernel in the cache and will be loaded if it's already present. |
30 | | -However, if the program is seeking for a kernel that has been evicted, the |
31 | | -algorithm will load it from the file and enqueue in the cache. |
| 17 | +---------- |
| 18 | + |
| 19 | +The caching mechanism for ``numba-dpex`` works as follows: The cache is an LRU |
| 20 | +cache backed by an ordered dictionary mapped onto a doubly linked list. The tail |
| 21 | +of the list contains the most recently used (MRU) kernel and the head of the |
| 22 | +list contains the least recently used (LRU) kernel. The list has a fixed size. |
| 23 | +If a new kernel arrives to be cached and if the size is already on the maximum |
| 24 | +limit, the algorithm evicts the LRU kernel to make room for the MRU kernel. The |
| 25 | +evicted item will be serialized and pickled into a file using Numba's caching |
| 26 | +mechanism. |
| 27 | + |
| 28 | +Everytime when a kernel needs to be retrieved from the cache, the mechanism |
| 29 | +will look for the kernel in the cache and will be loaded if it's already |
| 30 | +present. However, if the program is seeking for a kernel that has been evicted, |
| 31 | +the algorithm will load it from the file and enqueue in the cache. As a result, |
| 32 | +the amount of file operations are significantly lower than that of Numba. |
32 | 33 |
|
33 | 34 | Settings |
34 | | --------- |
| 35 | +--------- |
35 | 36 |
|
36 | | -Therefore, we employ similar environment variables as used in Numba, |
37 | | -i.e. ``NUMBA_CACHE_DIR`` etc. However we add three more environment variables to |
38 | | -control the caching mechanism. |
| 37 | +Therefore, ``numba-dpex`` employs similar environment variables as used in |
| 38 | +Numba, i.e. ``NUMBA_CACHE_DIR`` etc. However there are three more environment |
| 39 | +variables to control the caching mechanism. |
39 | 40 |
|
40 | | -- In order to specify cache capacity, one can use ``NUMBA_DPEX_CACHE_SIZE``. |
41 | | -By default, it's set to 10. |
| 41 | +- In order to specify cache capacity, ``NUMBA_DPEX_CACHE_SIZE`` can be used. By |
| 42 | + default, it's set to 10. |
42 | 43 |
|
43 | | -- ``NUMBA_DPEX_ENABLE_CACHE`` can be used to enable/disable the caching mechanism. |
44 | | -By default it's enabled, i.e. set to 1. |
| 44 | +- ``NUMBA_DPEX_ENABLE_CACHE`` can be used to enable/disable the caching |
| 45 | + mechanism. By default it's enabled, i.e. set to 1. |
45 | 46 |
|
46 | | -- In order to enable the debugging messages related to caching, one can set |
47 | | -``NUMBA_DPEX_DEBUG_CACHE`` to 1. All environment variables are defined in |
48 | | -:file:`numba_dpex/config.py`. |
| 47 | +- In order to enable the debugging messages related to caching, the variable |
| 48 | +``NUMBA_DPEX_DEBUG_CACHE`` can be set to 1. All environment variables are |
| 49 | +defined in :file:`numba_dpex/config.py`. |
0 commit comments