GeNNDevice class¶
(Shortest import: from brian2genn.device import GeNNDevice)
-
class
brian2genn.device.
GeNNDevice
[source]¶ Bases:
brian2.devices.cpp_standalone.device.CPPStandaloneDevice
The main “genn” device. This does most of the translation work from Brian 2 generated code to functional GeNN code, assisted by the “GeNN language”.
Attributes
source_files
List of all source and header files (to be included in runner) Methods
activate
([build_on_run])Called when this device is set as the current device. add_array_variable
(model, varname, variable)add_array_variables
(model, owner)add_parameter
(model, varname, variable)build
([directory, compile, run, use_GPU, …])This function does the main post-translation work for the genn device. code_object
(owner, name, abstract_code, …)Processes abstract code into code objects and stores them in different arrays for GeNNCodeObjects
andGeNNUserCodeObjects
.code_object_class
([codeobj_class])Return CodeObject
class (eitherCPPStandaloneCodeObject
class or input)collect_synapses_variables
(synapse_model, …)compile_source
(debug, directory, use_GPU)copy_source_files
(writer, directory)fill_with_array
(var, arr)Fill an array with the values given in another array. fix_random_generators
(model, code)Translates cpp_standalone style random number generator calls into GeNN- compatible calls by replacing the cpp_standalone _vectorisation_idx
argument with the GeNN_seed
argument.fix_synapses_code
(synapse_model, pathway, …)generate_code_objects
(writer)generate_engine_source
(writer)generate_main_source
(writer, main_lines)generate_makefile
(directory, use_GPU)generate_model_source
(writer)generate_objects_source
(arange_arrays, net, …)insert_code
(slot, code)Insert custom C++ code directly into main.cpp
.make_main_lines
()Generates the code lines that handle initialisation of Brian 2 cpp_standalone type arrays. network_run
(net, duration[, report, …])process_neuron_groups
(neuron_groups, objects)process_poisson_groups
(objects, poisson_groups)process_rate_monitors
(rate_monitors)process_spike_monitors
(spike_monitors)process_spikegenerators
(spikegenerator_groups)process_state_monitors
(directory, …)process_synapses
(synapse_groups)run
(directory, use_GPU, with_output)variableview_set_with_expression
(…[, …])variableview_set_with_expression_conditional
(…)variableview_set_with_index_array
(…)Details
-
source_files
¶ List of all source and header files (to be included in runner)
-
activate
(build_on_run=True, **kwargs)[source]¶ Called when this device is set as the current device.
-
build
(directory='GeNNworkspace', compile=True, run=True, use_GPU=True, debug=False, with_output=True, direct_call=True)[source]¶ This function does the main post-translation work for the genn device. It uses the code generated during/before run() and extracts information about neuron groups, synapse groups, monitors, etc. that is then formatted for use in GeNN-specific templates. The overarching strategy of the brian2genn interface is to use cpp_standalone code generation and templates for most of the “user-side code” (in the meaning defined in GeNN) and have GeNN-specific templates for the model definition and the main code for the executable that pulls everything together (in main.cpp and engine.cpp templates). The handling of input/output arrays for everything is lent from cpp_standalone and the cpp_standalone arrays are then translated into GeNN-suitable data structures using the static (not code-generated) b2glib library functions. This means that the GeNN specific cod only has to be concerned about executing the correct model and feeding back results into the appropriate cpp_standalone data structures.
-
code_object
(owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class=None, template_kwds=None, override_conditional_write=None, **kwds)[source]¶ Processes abstract code into code objects and stores them in different arrays for
GeNNCodeObjects
andGeNNUserCodeObjects
.
-
code_object_class
(codeobj_class=None, *args, **kwds)[source]¶ Return
CodeObject
class (eitherCPPStandaloneCodeObject
class or input)Parameters: codeobj_class : a
CodeObject
class, optionalIf this is keyword is set to None or no arguments are given, this method will return the default (
CPPStandaloneCodeObject
class).fallback_pref : str, optional
For the cpp_standalone device this option is ignored.
Returns: codeobj_class : class
The
CodeObject
class that should be used
-
fill_with_array
(var, arr)[source]¶ Fill an array with the values given in another array.
Parameters: var :
ArrayVariable
The array to fill.
arr :
ndarray
The array values that should be copied to
var
.
-
fix_random_generators
(model, code)[source]¶ Translates cpp_standalone style random number generator calls into GeNN- compatible calls by replacing the cpp_standalone
_vectorisation_idx
argument with the GeNN_seed
argument.
-
insert_code
(slot, code)[source]¶ Insert custom C++ code directly into
main.cpp
. The available slots are:before_start
/after_start
- Before/after allocating memory for the arrays and loading arrays from disk.
before_run
/after_run
- Before/after calling GeNN’s
run
function. before_end
/after_end
- Before/after writing results to disk and deallocating memory.
Parameters: slot : str
The name of the slot where the code will be placed (see above for list of available slots).
code : str
The C++ code that should be inserted.
-
make_main_lines
()[source]¶ Generates the code lines that handle initialisation of Brian 2 cpp_standalone type arrays. These are then translated into the appropriate GeNN data structures in separately generated code.
-
network_run
(net, duration, report=None, report_period=10. * second, namespace=None, profile=False, level=0, **kwds)[source]¶
-
variableview_set_with_expression
(variableview, item, code, run_namespace, check_units=True)[source]¶
-