pyjac.core.shared_memory module¶
Handles shared memory usage to accelerate memory accesses for CUDA
-
class
pyjac.core.shared_memory.
variable
(base, index, lang='cuda')[source]¶ Bases:
object
Class that represents an array/index pair. Used for in the internal dicitonary of the
shared_memory_manager
for identification and tracking ofvariable
usage for eviction.Creates a
variable
with given base and indexParameters:
-
class
pyjac.core.shared_memory.
shared_memory_manager
(blocks_per_sm=8, num_threads=64, L1_PREFERRED=True)[source]¶ Bases:
object
Manager for GPU shared memory.
Creates a shared memory manager
Parameters: Notes
For ease, a single SMM is used in the entire program. Thus this class has methods for setting the state/behaviour (e.g.,
reset
, andset_on_eviction
).-
force_eviction
()[source]¶ Forces eviction of the manager’s internal dictionary.
Notes
The internal dictionary will be reset, and (if supplied) the
on_eviction
function will be called on each evicted entry.
-
evict
(shared_index)[source]¶ Removes the entry at shared_index from the internal dictionary
Parameters: shared_index (int) – The key to remove from the internal dictionary Notes
If set,
on_eviction
will be called.
-
add_to_dictionary
(val)[source]¶ Adds the value to the next available dictionary location
Parameters: val ( variable
) – The value to add to the dictionary
-
set_on_eviction
(func)[source]¶ - Sets a callback function that is called upon eviction of a variable from the
- internal dictionary
Parameters: func ( function
) – Function that takes one arguement (the evicted variable)Returns: Return type: None
-
write_init
(file, indent=4)[source]¶ Convenience method to define shared memory for CUDA
Parameters: - file (
File
) – OpenFile
object to write to - indent (int, optional) – The number of spaces to use in the indent
Returns: Return type: None
- file (
-
load_into_shared
(file, variables, estimated_usage=None, indent=2, load=True)[source]¶ The main SMM method, loads/evicts variables based upon estimated usage and stagnancy.
Parameters: - file (
File
) – OpenFile
object to write to - variables (list of
variable
) – List of variables to consider loading - estimated_usage (list of float, optional) – If specified, these will be used to prioritize variable additon
- indent (int, optional) – The number of spaces to use in the indentation
- load (bool, optional) – If
True
(default), a load into the internal dictionary will be written to the file. IfFalse
, this will must be handled by the calling routine.
Returns: Return type: List of
bool
to indicate if variables are loaded in shared memory.- file (
-
mark_for_eviction
(variables)[source]¶ Marks variables for possible eviction upon next load_into_shared call
Parameters: variables (list of variable
) – List of variables to consider for eviction
-
get_index
(var)[source]¶ Checks to see if a variable is in the internal dictionary. If so returns internal index and variable
Parameters: var ( variable
) – The variable to checkReturns: - our_ind (int) – Index of variable in internal dictionary
- our_var (
variable
) – Variable found in internal dictionary
-
get_array
(lang, thevar, index, twod=None)[source]¶ A substitute for
utils.get_array
.If the variable is in our internal dictionary returns shared memory address, otherwise calls
utils.get_array
.Parameters: Returns: name – String with indexed array.
Return type:
-