brainpy.math.XLACustomOp#
- class brainpy.math.XLACustomOp(eval_shape=None, con_compute=None, cpu_func=None, gpu_func=None, apply_cpu_func_to_gpu=None, name=None, batching_translation=None, jvp_translation=None, transpose_translation=None, multiple_results=True)[source]#
Creating a XLA custom call operator.
- Parameters:
name (str) – The name of operator.
eval_shape (callable) –
The function to evaluate the shape and dtype of the output according to the input. This function should receive the abstract information of inputs, and return the abstract information of the outputs. For example:
>>> def eval_shape(inp1_info, inp2_info, inp3_info, ...): >>> return out1_info, out2_info
con_compute (callable) –
The function to make the concrete computation. This function receives inputs, and returns outputs. For example:
>>> def con_compute(inp1, inp2, inp3, ...): >>> return out1, out2
cpu_func (callable) – The function defines the computation on CPU backend. Same as
con_compute
.gpu_func (callable) – The function defines the computation on GPU backend. Currently, this function is not supportted.
apply_cpu_func_to_gpu (bool) –
Whether allows to apply CPU function on GPU backend. If True, the GPU data will move to CPU, and after calculation, the returned outputs on CPU backend will move to GPU.
Deprecated since version 2.2.4.1: No longer supported.
- __init__(eval_shape=None, con_compute=None, cpu_func=None, gpu_func=None, apply_cpu_func_to_gpu=None, name=None, batching_translation=None, jvp_translation=None, transpose_translation=None, multiple_results=True)[source]#
Methods
__init__
([eval_shape, con_compute, ...])cpu
()Move all variable into the CPU device.
cuda
()Move all variables into the GPU device.
load_state_dict
(state_dict[, warn, compatible])Copy parameters and buffers from
state_dict
into this module and its descendants.load_states
(filename[, verbose])Load the model states.
nodes
([method, level, include_self])Collect all children nodes.
register_implicit_nodes
(*nodes[, node_cls])register_implicit_vars
(*variables[, var_cls])save_states
(filename[, variables])Save the model states.
state_dict
()Returns a dictionary containing a whole state of the module.
to
(device)Moves all variables into the given device.
tpu
()Move all variables into the TPU device.
train_vars
([method, level, include_self])The shortcut for retrieving all trainable variables.
tree_flatten
()Flattens the object as a PyTree.
tree_unflatten
(aux, dynamic_values)Unflatten the data to construct an object of this class.
unique_name
([name, type_])Get the unique name for this object.
vars
([method, level, include_self, ...])Collect all variables in this node and the children nodes.
Attributes
name
Name of the model.