You can also use replacement in string like this:

"%(REAL)s var = 0;"%{"REAL":"float"}

We use that extensively in Theano and work such small change in the code.

Fred

On Mon, Jun 6, 2011 at 8:50 AM, Bogdan Opanchuk <[email protected]> wrote:
> Hello Irwin,
>
> On Mon, Jun 6, 2011 at 2:16 PM, Irwin Zaid <[email protected]> 
> wrote:
>> Anyway, I was wondering if there is a better way to provide this
>> functionality? In normal CUDA code, this could be done with templates, but
>> that doesn't seem to be an option here. I know metaprogramming is a
>> solution, but I'd like to avoid that as it seems like an unnecessarily large
>> solution to a tiny problem. (And I don't want to require additional
>> dependencies like jinja2, mako, etc...)
>>
>> Am I simply stuck maintaining two kernels that are nearly identical?
>
> I do not really see why are you calling metaprogramming a "large
> solution". Basically it is the same as using printf() to construct
> printed string in runtime. If you do not want to require third-party
> templating packages, you can just use Python's format() function ---
> it seems that it will be enough for your purposes.
>
> Best regards,
> Bogdan
>
> _______________________________________________
> PyCUDA mailing list
> [email protected]
> http://lists.tiker.net/listinfo/pycuda
>

_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to