Skip to content

Commit

Permalink
Merge pull request #600 from brian-team/efficient_synapse_creation
Browse files Browse the repository at this point in the history
Efficient synapse creation
  • Loading branch information
mstimberg committed Apr 9, 2016
2 parents 70c0644 + 4a1cdc9 commit 5c036df
Show file tree
Hide file tree
Showing 58 changed files with 2,705 additions and 1,043 deletions.
44 changes: 21 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ environment:
secure: mP9XvwSNUqxq7cFK4V0wM2rNmvlGUYecSlZvkYjRtdGotr9ueS2IycSDvvNGlSdK

matrix:
- PYTHON: "C:\\Python34-conda32"
PYTHON_VERSION: "3.4.3"
- PYTHON: "C:\\Miniconda3"
PYTHON_VERSION: "3.4"
PYTHON_ARCH: "32"
platform: x86
STANDALONE: "FALSE"
Expand All @@ -20,8 +20,8 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "FALSE"

- PYTHON: "C:\\Python34-conda64"
PYTHON_VERSION: "3.4.3"
- PYTHON: "C:\\Miniconda3-x64"
PYTHON_VERSION: "3.4"
PYTHON_ARCH: "64"
platform: x64
STANDALONE: "FALSE"
Expand All @@ -30,8 +30,8 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "FALSE"

- PYTHON: "C:\\Python35-conda32"
PYTHON_VERSION: "3.5.0"
- PYTHON: "C:\\Miniconda35"
PYTHON_VERSION: "3.5"
PYTHON_ARCH: "32"
platform: x86
STANDALONE: "FALSE"
Expand All @@ -40,8 +40,8 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "FALSE"

- PYTHON: "C:\\Python35-conda64"
PYTHON_VERSION: "3.5.0"
- PYTHON: "C:\\Miniconda35-x64"
PYTHON_VERSION: "3.5"
PYTHON_ARCH: "64"
platform: x64
STANDALONE: "FALSE"
Expand All @@ -50,8 +50,8 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "FALSE"

- PYTHON: "C:\\Python27-conda32"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "32"
platform: x86
STANDALONE: "FALSE"
Expand All @@ -60,16 +60,16 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "1"

- PYTHON: "C:\\Python27-conda32"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "32"
platform: x86
STANDALONE: "FALSE"
CONDA_BUILD: "FALSE"
SPLIT_RUN: "2"

- PYTHON: "C:\\Python27-conda64"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "64"
platform: x64
STANDALONE: "FALSE"
Expand All @@ -78,31 +78,29 @@ environment:
CONDA_BUILD: "TRUE"
SPLIT_RUN: "1"

- PYTHON: "C:\\Python27-conda64"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "64"
platform: x64
STANDALONE: "FALSE"
CONDA_BUILD: "FALSE"
SPLIT_RUN: "2"

- PYTHON: "C:\\Python27-conda32"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "32"
platform: x86
STANDALONE: "TRUE"

- PYTHON: "C:\\Python27-conda64"
PYTHON_VERSION: "2.7.10"
- PYTHON: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7"
PYTHON_ARCH: "64"
platform: x64
STANDALONE: "TRUE"

install:
# Install Python and miniconda
- 'powershell .\dev\continuous-integration\appveyor\install_python.ps1'
# Add the paths
- 'set PATH=%PYTHON%;%PYTHON%/Scripts;%PATH%'
- 'set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%'
# Create a new environment with the exact Python version and activate it
- 'conda create --yes --quiet -n appveyor_test python=%PYTHON_VERSION%'
- 'activate appveyor_test'
Expand Down
3 changes: 2 additions & 1 deletion brian2/codegen/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def translate(self, code, dtype):
statements = make_statements(ac_code,
self.variables,
dtype,
optimise=True)
optimise=True,
blockname=ac_name)
scalar_statements[ac_name], vector_statements[ac_name] = statements
for vs in vector_statements.itervalues():
# Check that the statements are meaningful independent on the order of
Expand Down
17 changes: 14 additions & 3 deletions brian2/codegen/generators/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def c_data_type(dtype):
}}
'''.format(hightype=hightype, xtype=xtype, ytype=ytype, expr=expr)

_universal_support_code = deindent(mod_support_code)+'''
#ifdef _MSC_VER
#define _brian_pow(x, y) (pow((double)(x), (y)))
#else
#define _brian_pow(x, y) (pow((x), (y)))
#endif
'''


class CPPCodeGenerator(CodeGenerator):
'''
Expand All @@ -133,7 +141,7 @@ class CPPCodeGenerator(CodeGenerator):

class_name = 'cpp'

universal_support_code = deindent(mod_support_code)
universal_support_code = _universal_support_code

def __init__(self, *args, **kwds):
super(CPPCodeGenerator, self).__init__(*args, **kwds)
Expand Down Expand Up @@ -361,8 +369,12 @@ def determine_keywords(self):
continue
if getattr(var, 'dimensions', 1) > 1:
continue # multidimensional (dynamic) arrays have to be treated differently
restrict = self.restrict
# turn off restricted pointers for scalars for safety
if var.scalar:
restrict = ' '
line = '{0}* {1} {2} = {3};'.format(self.c_data_type(var.dtype),
self.restrict,
restrict,
pointer_name,
array_name)
pointers.append(line)
Expand Down Expand Up @@ -418,7 +430,6 @@ def determine_keywords(self):
code=None,
name=func_cpp)


abs_code = '''
#define _brian_abs std::abs
'''
Expand Down
15 changes: 11 additions & 4 deletions brian2/codegen/optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def expression_complexity(expr, variables):
return brian_ast(expr, variables).complexity


def optimise_statements(scalar_statements, vector_statements, variables):
def optimise_statements(scalar_statements, vector_statements, variables, blockname=''):
'''
Optimise a sequence of scalar and vector statements
Expand All @@ -62,6 +62,8 @@ def optimise_statements(scalar_statements, vector_statements, variables):
Statements that involve vector values and should be evaluated in the vector block.
variables : dict of (str, Variable)
Definition of the types of the variables.
blockname : str, optional
Name of the block (used for LIO constant prefixes to avoid name clashes)
Returns
-------
Expand All @@ -74,7 +76,7 @@ def optimise_statements(scalar_statements, vector_statements, variables):
if hasattr(v, 'dtype') and brian_dtype_from_dtype(v.dtype)=='boolean')
# We use the Simplifier class by rendering each expression, which generates new scalar statements
# stored in the Simplifier object, and these are then added to the scalar statements.
simplifier = Simplifier(variables, scalar_statements)
simplifier = Simplifier(variables, scalar_statements, extra_lio_prefix=blockname)
new_vector_statements = []
for stmt in vector_statements:
# Carry out constant evaluation, arithmetic simplification and loop invariants
Expand Down Expand Up @@ -295,14 +297,19 @@ class Simplifier(BrianASTRenderer):
``loop_invariant_dtypes`` : dict of (varname, dtypename)
dtypename will be one of ``'boolean'``, ``'integer'``, ``'float'``.
'''
def __init__(self, variables, scalar_statements):
def __init__(self, variables, scalar_statements, extra_lio_prefix=''):
BrianASTRenderer.__init__(self, variables)
self.loop_invariants = OrderedDict()
self.loop_invariant_dtypes = {}
self.n = 0
self.node_renderer = NodeRenderer(use_vectorisation_idx=False)
self.arithmetic_simplifier = ArithmeticSimplifier(variables)
self.scalar_statements = scalar_statements
if extra_lio_prefix is None:
extra_lio_prefix = ''
if len(extra_lio_prefix):
extra_lio_prefix = extra_lio_prefix+'_'
self.extra_lio_prefix = extra_lio_prefix

def render_expr(self, expr):
node = brian_ast(expr, self.variables)
Expand All @@ -321,7 +328,7 @@ def render_node(self, node):
name = self.loop_invariants[expr]
else:
self.n += 1
name = '_lio_'+str(self.n)
name = '_lio_'+self.extra_lio_prefix+str(self.n)
self.loop_invariants[expr] = name
self.loop_invariant_dtypes[name] = node.dtype
numpy_dtype = {'boolean': bool,
Expand Down
89 changes: 0 additions & 89 deletions brian2/codegen/runtime/cython_rt/templates/synapses_create.pyx

This file was deleted.

Loading

0 comments on commit 5c036df

Please sign in to comment.