Code Monkey home page Code Monkey logo

Comments (24)

thesamovar avatar thesamovar commented on July 17, 2024

Have you checked if this actually happens? I don't think it should. But you mention variables that are introduced in code: what do you mean by this? Persistent variables have to be defined in model strings, not code strings. The only variables introduced in code strings should be temporary variables that have a scope local to that code block.

And just in case he's not subscribed - any thoughts @mstimberg ?

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Hi Dan, @mstimberghttps://github.com/mstimberg
I am not sure that this really happens. What I meant is that I add the variables provided with the _pre and _post code objects incrementally to my own structure. But I use this structure already for generating the “pre” code before adding the variables from the “post" code object … anyway, it’s not a problem if Brian has already sorted out all necessary variables for each code object no matter where they first appeared …

In other news, the pre-defined variables have now been removed from GeNN and brian2genn passes two tests: Euler integration and pre-synaptic code. I am not sure why linear integration fails…

(pull newest brian2genn “develop” branch and genn “development” branch.

Cheers,
Thomas.

Prof. Thomas Nowotny
CCNR, Sussex Neuroscience Phone: +44-1273-678593
Engineering and Informatics Fax: +44-1273-877873
University of Sussex
Falmer, Brighton BN1 9QJ http://sussex.ac.uk/informatics/tnowotny

From: Dan Goodman <[email protected]mailto:[email protected]>
Reply-To: brian-team/brian2genn <[email protected]mailto:[email protected]>
Date: Monday, 10 November 2014 15:35
To: brian-team/brian2genn <[email protected]mailto:[email protected]>
Cc: Thomas Nowotny <[email protected]mailto:[email protected]>
Subject: Re: [brian2genn] Are there stituations where variables are not decorated because of mixed variable usage? (#17)

Have you checked if this actually happens? I don't think it should. But you mention variables that are introduced in code: what do you mean by this? Persistent variables have to be defined in model strings, not code strings. The only variables introduced in code strings should be temporary variables that have a scope local to that code block.

And just in case he's not subscribed - any thoughts @mstimberghttps://github.com/mstimberg ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/17#issuecomment-62401251.

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

I'm not quite sure I understand this issue. Brian collects all the variables that are used in a code string, this collection is completely independent between the pre and the post string. As Dan said, you cannot introduce variables in one code string and use them in the other, newly introduced variables are only temporary and local.

I am not sure why linear integration fails…

It seems to be due to its use of exp which is resolved to std::exp instead of the CUDA math function because of the using namespace std; in runner.h.

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Hi - maybe let's not worry about the issue I raised as it may well be a non-issue and if it is it will crop up and be very clear (non-decorated variables - very easy to spot).
I am not sure I understand the explanation around differently resolved exp functions - what you said should not happen no matter which using directives are provided if the exp functions appears in kernel code (i.e. after global keyword). How can I get my hands on the full traceback of the failed call of this test?

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

I am not sure I understand the explanation around differently resolved exp functions - what you said should not happen no matter which using directives are provided if the exp functions appears in kernel code (i.e. after global keyword). How can I get my hands on the full traceback of the failed call of this test?

I don't have much experience with this, exp is in the __global__ code but the error message complains about it being a host function:

dry-run compile for device 0
"/usr/bin/nvcc" -x cu -cubin -Xptxas=-v -DDT -arch=sm_13 /home/marcel/programming/brian2genn/brian2genn/testing_dir/magicnetwork_model_CODE/runner.cc 2>&1
/home/marcel/programming/brian2genn/brian2genn/testing_dir/magicnetwork_model_CODE/neuronKrnl.cc(50): warning: variable "Isyn" was declared but never referenced

/home/marcel/programming/brian2genn/brian2genn/testing_dir/magicnetwork_model_CODE/neuronKrnl.cc(74): warning: variable "shSpkEvnt" is used before its value is set

/home/marcel/programming/brian2genn/brian2genn/testing_dir/magicnetwork_model_CODE/neuronKrnl.cc(24): warning: variable "spkEvntIdx" was declared but never referenced

/home/marcel/programming/brian2genn/brian2genn/testing_dir/magicnetwork_model_CODE/neuronKrnl.cc(54) (col. 20): error: calling a __host__ function("std::exp<int> ") from a __global__ function("calcNeurons") is not allowed

I don't think we currently have a convenient way of getting the full error output for failed tests in the feature test (in this case the problem is also that the call statements in the build function simply return a non-zero value if the executed command fails). For getting the above message I ran the feature test suite only for the failing test (feature_tests=[NeuronGroupIntegrationLinear]) and then manually ran buildmodel.sh magicnetwork_model in brian2genn/testing_dir.

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Aha ... that's where it's going wrong: CUDA does not have a exp(int) function (only floating point arguments are supported). The compiler then defaults to the std:exp(int) header rather than doing an auto cast from int to float (or double). Hum ... I wonder what would happen if we provided an appropriate device and host function:
device host float exp(int i) { return exp((float) i); }

... turns out it works!

But I do not understand it at all: For some reason "exp(-(0.001) / 1)" resolves to exp(int) - but the argument surely isn't and int!?! What am I missing here?
(latest version of brian2genn and genn should pass 3 tests)

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Now the 100mio $ question is: Do we need this for all commonly used functions? Very strange all this.

from brian2genn.

thesamovar avatar thesamovar commented on July 17, 2024

I just came up against this same issue with ints and floats. Take a look at the discussion in brian-team/brian2#368.

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Hum ... still doesn't answer the question why "-(0.001)/1" is interpreted as an int. Alomst seems like a compiler error. I'll let it simmer for a bit - but likely will end up providing the wrapper functions that cast to float whenever there is an int argument detected. Where can I find the list of standard math functions that Brian2 would support?

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

Hum ... still doesn't answer the question why "-(0.001)/1" is interpreted as an int.

I think I figured this one out: it's very specific to the case of DT which is passed as a compiler argument with -DDT and therefore has the value 1 -- I'm not quite sure where this is coming from but I guess it is what GeNN used for the global dt value?

from brian2genn.

thesamovar avatar thesamovar commented on July 17, 2024

That would make sense: GeNN has time in units of ms rather than s.

The list of default functions is here: http://brian2.readthedocs.org/en/2.0beta/user/functions.html

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

That would make sense: GeNN has time in units of ms rather than s.

It's not that, it's set in the compiler call with -DDT, this automatically sets it to the integer value 1. It's also set in the code (to the correct value) with #define DT.

from brian2genn.

jamesturner246 avatar jamesturner246 commented on July 17, 2024

The -DDT flag is a placeholder, arbitrarily set to one, which is used while the generateALL program "dry-run" compiles the generated code to find out CUDA register and shared memory usage.

The final value of DT is defined in the user's model definition file (the one with the modelDefinition function).

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Ok ... we are on the right track. The compiler call with -DDT is a "bogus compilation" we do in our process of estimating register usage in kernels etc in blocksize optimisation. I am not sure why -DDT is there to be honest (James did this part) but am testing whether it can be removed. In the actual compilation the DT is set in the generated code.
I will do some testing now.

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

James, but why do we need this? As it's causing problems can we remove it from this call (I am testing this as we speak).

from brian2genn.

jamesturner246 avatar jamesturner246 commented on July 17, 2024

It needed to be there because the generated code contains DT in places. We could give DT upfront inside the modelDefinition() function (with some default value, otherwise), and then replace DT with this value in the generated code.

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

Maybe for the problem at hand, just setting it to a different placeholder value such as 0.1 would solve the issue?

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

Oh and about adding support for integers to functions (we should probably continue to discuss this in brian-team/brian2#368 since it is not only an issue for GeNN): using the current mechanism, you can add specific function implementations for GeNN. Either a function code (that could use templates), such as this variant of what Dan did in the support_msvc branch (for GeNN there needs to be also __global__ somewhere, I guess):

abs_code = '''
template<class X>
inline X _abs(X &x)
{
    return fabs((double)x);
}
'''
DEFAULT_FUNCTIONS['abs'].implementations.add_implementation(GeNNCodeGenerator,
                                                            code=abs_code,
                                                            name='_abs')

Alternatively, a simpler preprocessor macro should work here as well, I think:

abs_code = {'hashdefine_code': '#define _abs(X) fabs((double)(X))'}
DEFAULT_FUNCTIONS['abs'].implementations.add_implementation(GeNNCodeGenerator,
                                                            code=abs_code,
                                                            name='_abs')

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Ok ... for now the specific problem is fixed. I took the freedom to define the actual value of DT in that compiler line (as it's knwon at that stage anyway). Latest version of Genn development branch now passing 3 tests without awkward wrappers for int functions. We will think about the int function problem as a general topic a bit longer.

from brian2genn.

thesamovar avatar thesamovar commented on July 17, 2024

I should also add that that code doesn't work for many compilers but it does if you replace X &x with X x but I'm still not happy with it.

from brian2genn.

thesamovar avatar thesamovar commented on July 17, 2024

That's great! We should add some new tests to make it harder for you now. :)

from brian2genn.

mstimberg avatar mstimberg commented on July 17, 2024

I should also add that that code doesn't work for many compilers but it does if you replace X &x with X x but I'm still not happy with it.

I guess it should work with const X &x maybe?

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

Yes - more tests and I guess we need to get cracking at the aditional features that the existing 3 tests need. Post-synaptic code should actually be running now - so potentially I'll remove the "not implemented warning" and start testing.

from brian2genn.

tnowotny avatar tnowotny commented on July 17, 2024

I am not sure where you eventually got to with the integer arguments for functions but as the interface is heavily leaning on the current cpp_standalone solution it should likely be ok. I will close this for now.

from brian2genn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.