December 16, 2006
Knud Sørensen wrote:
> I expect for the array operation in 2.0 is something like vectorization.
> see http://www.all-technology.com/eigenpolls/dwishlist/index.php?it=10
> 
> Which allows you (in one line) to make multidimensional calculations on
> an arbitrary number of multidimensional arrays, but it still allows you to read exactly which indexed is used and the exact calculation performed. 
> 
> The syntax don't generate temporary arrays and allow the compiler to freely reorder nested loops.

This doesn't generate temporary arrays either. The point is, that with this bit of syntax sugar, we could use expression templates to do virtually all of this stuff. Vectorisation is notoriously difficult for compilers to do well without help; this is an easy way of assisting the compiler.

> Also the compiler will be free to support for SSE? and GPUs in the future without your having to rewriting the
> vectorization code.
>  I don't expect to see this in 1.0 I am just pointing out that the array operation you suggest here seems fare from my expectations for 2.0.



> 
> Knud
December 16, 2006
Bill Baxter wrote:
> Don Clugston wrote:
>> Array operations are one of the very few 2.0 features that haven't made it into 1.0. My experiments into expression templates suggest that it might not be very complicated after all.
>>
>> Consider something like a dot product,
>>
>> real a[], b[], c[];
>> real d = dot(a+b, c);
>>
>> For performance, it would be better if the compiler actually *didn't* evaluate a+b. Instead, that should compile to:
>>
>> real sum = 0;
>> for (int i=0; i<c.length; ++i) {
>>      sum+=(a[i]+b[i])*c[i];
>> }
>> d=sum;
>>
>> In fact, we could create a fantastic library implementation of array operations with a tiny bit of syntactic sugar:
>> instead of generating an error message for array operations, look for an opXXX function, and treat it the same way the implicit array properties work.
> 
> How does that result in the above code for dot product?
> Looks to me like if all you have is calling opXXX functions the above dot would still become two loops with a tmp for the a+b.

I've posted an update to my expression templates code in dsource/mathextra/Blade.
It prints near-optimal x87 asm code for any combination of +,-,+=,-=, *, *= and dot product on double[] vectors.
The code is still less than 300 lines, so a comprehensive expression template system would probably not be too horrible.
December 16, 2006
Don Clugston wrote:
> Array operations are one of the very few 2.0 features that haven't made it into 1.0. My experiments into expression templates suggest that it might not be very complicated after all.

I've never properly got my head around this expression templates business.  Maybe I just need to read up on it a bit more.

<snip>
> In fact, we could create a fantastic library implementation of array operations with a tiny bit of syntactic sugar:
> instead of generating an error message for array operations, look for an opXXX function, and treat it the same way the implicit array properties work.
<snip>

True.  Having array operations built in would create plenty of optimisation potential, but having a library implementation with the help of a bit of syntactic sugar at the language level would at least work.

How many of you have seen my proposal from a while back?

http://www.digitalmars.com/d/archives/digitalmars/D/16647.html

Stewart.
1 2
Next ›   Last »