Skip to content

Commit

Permalink
Merge pull request #804 from IntelPython/refactor/kernel_interfaces
Browse files Browse the repository at this point in the history
Refactor/kernel interfaces
  • Loading branch information
Diptorup Deb authored Jan 18, 2023
2 parents ada8f19 + c74ea24 commit 187782d
Show file tree
Hide file tree
Showing 58 changed files with 3,236 additions and 1,577 deletions.
24 changes: 24 additions & 0 deletions docs/developer_guides/caching.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _caching:

Caching Mechanism in Numba-dpex
================================

Caching is done by saving the compiled kernel code, the ELF object of the executable code. By using the kernel code, cached kernels have minimal overhead because no compilation is needed.

Unlike Numba, we do not perform file-based caching, instead we use an Least Recently Used (LRU) caching mechanism. However when a kernel needs to be evicted, we utilize numba's file-based caching mechanism described `here <https://numba.pydata.org/numba-doc/latest/developer/caching.html>`_.

Algorithm
==========

The caching mechanism for Numba-dpex works as follows: The cache is an LRU cache backed by an ordered dictionary mapped onto a doubly linked list. The tail of the list contains the most recently used (MRU) kernel and the head of the list contains the least recently used (LRU) kernel. The list has a fixed size. If a new kernel arrives to be cached and if the size is already on the maximum limit, the algorithm evicts the LRU kernel to make room for the MRU kernel. The evicted item will be serialized and pickled into a file using Numba's caching mechanism.

Everytime whenever a kernel needs to be retrieved from the cache, the mechanism will look for the kernel in the cache and will be loaded if it's already present. However, if the program is seeking for a kernel that has been evicted, the algorithm will load it from the file and enqueue in the cache.

Settings
========

Therefore, we employ similar environment variables as used in Numba, i.e. ``NUMBA_CACHE_DIR`` etc. However we add three more environment variables to control the caching mechanism.

- In order to specify cache capacity, one can use ``NUMBA_DPEX_CACHE_SIZE``. By default, it's set to 10.
- ``NUMBA_DPEX_ENABLE_CACHE`` can be used to enable/disable the caching mechanism. By default it's enabled, i.e. set to 1.
- In order to enable the debugging messages related to caching, one can set ``NUMBA_DPEX_DEBUG_CACHE`` to 1. All environment variables are defined in :file:`numba_dpex/config.py`.
3 changes: 3 additions & 0 deletions numba_dpex/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def _init(self, llvm_module):
assert list(llvm_module.global_variables) == [], "Module isn't empty"
self._data_layout = SPIR_DATA_LAYOUT[utils.MACHINE_BITS]
self._target_data = ll.create_target_data(self._data_layout)
self._tm_features = (
"" # We need this for chaching, not sure about this value for now
)

def _create_empty_module(self, name):
ir_module = lc.Module(name)
Expand Down
Loading

0 comments on commit 187782d

Please sign in to comment.