This project is read-only.

Ordering types and 'identifier is undefined' errors

Sep 1, 2012 at 12:51 PM

First of all, I am a big fan of this project - clever stuff - thanks for sharing it!

I encountered a problem (not a bug) when calling a static method of a helper class from within a struct method in a different file - an identifier is undefined error - simply because in the .cu file the helper function appears further down than the struct code. There are plenty of ways around this of course, but I was curious as to whether there is any specific advice or work around this area and perhaps a 'Cudafy-approved' way of dealing with such things?

My current solution is to force certain types to appear earlier than others in the .cu file since Cudafy(params Type[] types) has its own rule set about what appears where (i.e. structs first). An alternative would be to add function prototypes to the start of the .cu file. I guess dependencies can also be inferred from the C# assembly too. Any thoughts or advice about any of this?



Sep 4, 2012 at 8:06 AM

Hi Joe,

Thanks for your support, much appreciated.

There are a number of scenarios when the normal functioning can break.  Methods from the same class are all put at top of cu file, what you've done breaks that.  We can take a look at handling this situation better.  Due to the power of .NET with reflection there is also scope for much smarter translation, but the question of whether something is worth the effort always looms.



Sep 4, 2012 at 10:40 PM

Thanks Nick,

Yes, I looked a little harder and as you say it's just that structs are placed in the cu file before declarations (presumably because structs often appear in the declarations). It might be possible to move just the declarations that do not involve structs to the top; I might have a look at this, although even that does not cover all cases (so more manual ordering might be better by your worth-the-effort argument!).