IntelLabs / RiverTrail

An API for data parallelism in JavaScript
Other
748 stars 71 forks source link

Why is the scalar element passed to the elemental function read-only? #32

Closed hujiajie closed 11 years ago

hujiajie commented 11 years ago

Take the follow code as an example :

var pa1 = new ParallelArray([1, 2, 3, 4]);
pa1.map(function (x) { x = 0; return 1; });

In the generated OpenCL code, the variable x is declared and initialized as

const double RTl_x = tempThis[_readoffset];

This means x cannot be modified in the elemental function and thus x = 0; would cause an OpenCL compiler error. So why is RTl_x declared as a const variable here? Is this restriction documented anywhere?

Thanks Jiajie

sherhut commented 11 years ago

This was a bug in code generation. The programming model does not prevent these variables from being modified in JavaScript. This is now also reflected in the code generation.

Stephan