-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created new Group._set_with_code_conditional will be needed for
standalone mode, works in runtime but not used automatically, doesn't work in standalone because _array_i is not defined
- Loading branch information
1 parent
00cc1d4
commit c5af402
Showing
7 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
brian2/codegen/runtime/numpy_rt/templates/group_variable_set_conditional.py_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Phase 1: we compute the indices where the conditional setting is to | ||
# be applied, and to do this we want to vectorise over all the values, | ||
# but we don't want to do the iterate all protocol, so we explicitly | ||
# set the idx to be slice(None) | ||
_vectorisation_idx = _idx = slice(None) | ||
{% for line in code_lines['condition'] %} | ||
{{line}} | ||
{% endfor %} | ||
|
||
# Phase 2: having computed _cond, the boolean array of points where | ||
# the setting is to be applied, we want to vectorise over idx being | ||
# only these values. | ||
_vectorisation_idx = _idx = _cond | ||
{% for line in code_lines['statement'] %} | ||
{{line}} | ||
{% endfor %} |
21 changes: 21 additions & 0 deletions
21
brian2/codegen/runtime/weave_rt/templates/group_variable_set_conditional.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% import 'common_macros.cpp' as common with context %} | ||
|
||
{% macro main() %} | ||
{{ common.insert_lines_commented('SUPPORT CODE', condition_support_code_lines) }} | ||
{{ common.insert_lines('HANDLE DENORMALS', condition_denormals_code_lines) }} | ||
{{ common.insert_lines('HASH DEFINES', condition_hashdefine_lines) }} | ||
{{ common.insert_lines('POINTERS', condition_pointers_lines) }} | ||
//// MAIN CODE //////////// | ||
for(int _idx=0; _idx<_num_idx; _idx++) | ||
{ | ||
const int _vectorisation_idx = _idx; | ||
{{ common.insert_lines('CONDITION', code_lines['condition']) }} | ||
if(_cond) { | ||
{{ common.insert_lines('STATEMENT', code_lines['statement']) }} | ||
} | ||
} | ||
{% endmacro %} | ||
|
||
{% macro support_code() %} | ||
{{ common.insert_lines('SUPPORT CODE', condition_support_code_lines) }} | ||
{% endmacro %} |
64 changes: 64 additions & 0 deletions
64
brian2/devices/cpp_standalone/templates/group_variable_set_conditional.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
//// MAIN CODE ///////////////////////////////////////////////////////////// | ||
|
||
{% macro cpp_file() %} | ||
|
||
#include "{{codeobj_name}}.h" | ||
#include<math.h> | ||
#include "brianlib/common_math.h" | ||
#include<stdint.h> | ||
|
||
////// SUPPORT CODE /////// | ||
namespace { | ||
{% for line in condition_support_code_lines %} | ||
{{line}} | ||
{% endfor %} | ||
} | ||
|
||
////// HASH DEFINES /////// | ||
{% for line in condition_hashdefine_lines %} | ||
{{line}} | ||
{% endfor %} | ||
|
||
void _run_{{codeobj_name}}(double t) | ||
{ | ||
///// CONSTANTS /////////// | ||
%CONSTANTS% | ||
///// POINTERS //////////// | ||
{% for line in condition_pointers_lines %} | ||
{{line}} | ||
{% endfor %} | ||
|
||
//// MAIN CODE //////////// | ||
const int _num_group_idx = _num_idx; | ||
for(int _idx_group_idx=0; _idx_group_idx<_num_group_idx; _idx_group_idx++) | ||
{ | ||
//const int _idx = _group_idx[_idx_group_idx]; | ||
const int _idx = _idx_group_idx; | ||
const int _vectorisation_idx = _idx; | ||
{% for line in code_lines['condition'] %} | ||
{{line}} | ||
{% endfor %} | ||
if(_cond) | ||
{ | ||
{% for line in code_lines['statement'] %} | ||
{{line}} | ||
{% endfor %} | ||
} | ||
} | ||
} | ||
{% endmacro %} | ||
|
||
//////////////////////////////////////////////////////////////////////////// | ||
//// HEADER FILE /////////////////////////////////////////////////////////// | ||
|
||
{% macro h_file() %} | ||
#ifndef _INCLUDED_{{codeobj_name}} | ||
#define _INCLUDED_{{codeobj_name}} | ||
|
||
#include "arrays.h" | ||
|
||
void _run_{{codeobj_name}}(double t); | ||
|
||
#endif | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters