D and Heterogeneous Computing

Josh Klontz josh.klontz at gmail.com
Tue Apr 10 17:59:26 PDT 2012


> From the looks of it this kind of stuff should be easy with 
> tokenzied strings ( q{ code } )+ mixins + some "auto-magic" 
> helpers being run for OpenCL behind the covers. The problematic 
> part is checking that the fragment is using the correct subset 
> of both languages.
>
> Ideally API should work along the lines of this:
>
> float[] arr1, arr2;
> //init arr1 & arr2
> assert(arr1.length == arr2.length);
> length = arr1.length;
> compute!q{
> 	for(int i=0;i<length; i++)
> 		arr1[i] += arr2[i];
> }(arr1, arr2);
>
> where compute works both with plain CPU and even without OpenCL 
> (by simply mixin stuff in) and for OpenCL with a bit of extra 
> binding magic inside compute template.
>
> (compute is an eponymous template that alied to static function 
> inside, that in turn is generated by mixin, for concrete 
> example - take a look on how ctRegex template in std.regex does 
> it)
>
> Of course, there are some painful details when you go for 
> deeper things and error messages but it should be perfectly 
> doable in normal D even w/o say CTFE parser.

Awesome, thanks! Will chew on this for a while :)


More information about the Digitalmars-d mailing list