numba_dpex.core.caching module

class numba_dpex.core.caching.AbstractCache

Bases: object

Abstract cache class to specify basic caching operations.

This class will be used to create an non-functional dummy cache (i.e. NullCache) and other functional cache. The dummy cache will be used as a placeholder when caching is disabled.

Args:
metaclass (type, optional): Metaclass for the abstract class.

Defaults to ABCMeta.

abstract get()

An abstract method to retrieve item from the cache.

abstract put(key, value)

An abstract method to save item into the cache.

Args:
key (object): The key for the data

(i.e. compiled kernel/function etc.).

value (object): The data (i.e. compiled kernel/function)

to be saved.

class numba_dpex.core.caching.LRUCache(name='cache', capacity=10, pyfunc=None)

Bases: AbstractCache

LRUCache implementation for caching kernels, functions and modules.

The cache is basically a doubly-linked-list backed with a dictionary as a lookup table.

clean()

Clean the cache

property evicted

Get the list of evicted items from the cache.

This is used for testing/debugging purposes.

Returns:

dict: A table of evicted items from the cache.

get(key)

Get the value associated with the key.

Args:

key (object): A key for the lookup table.

Returns:

object: The value associated with the key.

property head

Get the head of the cache.

This is used for testing/debugging purposes.

Returns:

Node: The head of the cache.

memsize()

Get the total memory size of the cache.

This function might be useful in the future when size based (not count based) cache limit will be implemented.

Returns:

int: Get the total memory size of the cache in bytes.

put(key, value)

Store the key-value pair into the cache.

Args:

key (object): The key for the data. value (object): The data to be saved.

size()

Get the current size of the cache.

Returns:

int: The current number of items in the cache.

property tail

Get the tail of the cache.

This is used for testing/debugging purposes.

Returns:

Node: The tail of the cache.

class numba_dpex.core.caching.Node(key, value)

Bases: object

A ‘Node’ class for LRUCache.

class numba_dpex.core.caching.NullCache

Bases: AbstractCache

A dummy cache used if user decides to disable caching.

If the caching is disabled this class will be used to perform all caching operations, all of which will be basically NOP. This idea is copied from numba.

Args:

AbstractCache (class): The abstract cache from which all other caching classes will be derived.

get(key)

Function to get an item (i.e. compiled kernel/function) from the cache

Args:
key (object): The key to retrieve the

data (i.e. compiled kernel/function)

Returns:

None: Returns None.

put(key, value)

Function to save a compiled kernel/function into the cache.

Args:

key (object): The key to the data (i.e. compiled kernel/function). value (object): The data to be cached (i.e. compiled kernel/function).