Hi Brian,
thanks a lot for your response ! Your solution works fine :) I messed up
declaration of input / output data in relation to uniforms.
Cheers
Petr
On Thursday, October 26, 2017 at 6:30:06 PM UTC+2, Brian Green wrote:
>
> I'm not sure I completely understand your input. Is srcRow an array of
> uniform float? In terms of output, is dstRow also an array of uniform
> float? If so the following function should work:
>
> void run(const uniform float * uniform srcRow, uniform int size, uniform
> float * uniform dstRow)
> {
> foreach (x = 0 ... size) {
> const float s0 = srcRow[max(0, x t 1)];
> const float s1 = srcRow[x];
> const float s2 = srcRow[min(size t 1, x + 1)];
>
> dstRow[x] = min(min(s0, s1), s2);
> }
>
> But will require gathers and generate performance warnings. You can avoid
> the gather warning by special casing the 0 and size - 1 entries:
>
> void run(const uniform float * uniform srcRow, uniform int size, uniform
> float * uniform dstRow)
> {
> foreach (x = 1 ... size - 1) {
> const float s0 = srcRow[x - 1];
> const float s1 = srcRow[x];
> const float s2 = srcRow[x + 1];
>
> dstRow[x] = min(min(s0, s1), s2);
> }
>
> // special case 0, and size -1
> dstRow[0] = min(srcRow[0], srcRow[1]);
> dstRow[size - 1] = min(srcRow[size - 1], srcRow[size - 2]);
> }
>
>
> -Brian
>
> On Tuesday, September 19, 2017 at 10:35:17 PM UTC-7, psmilek wrote:
>>
>> Hello guys,
>> I have following scenario which I don't know how to solve with ISPC. I
>> basically have 1D array of floats, which needs
>> to be processed. Processing one element involves accessing its neighbors,
>> so first and last element needs to
>> be treated in special way, as neighbors can be outside range of input
>> values.
>>
>> Code looks like this:
>>
>> ...
>>
>> foreach (x = 1 ... size - 1)
>> {
>> const float s0 = srcRow[x - 1];
>> const float s1 = srcRow[x];
>> const float s2 = srcRow[x + 1];
>>
>> dstRow[x] = min(min(s0, s1), s2);
>> }
>>
>> // Here is the problematic part. I want to compute 0th and (size -1)th
>> element, this time with 'clamp' style addressing (I also need to support
>> 'wrap' mode)
>> {
>> const float s0 = srcRow[0];
>> const float s1 = srcRow[0];
>> const float s2 = srcRow[1];
>>
>> dstRow[0] = min(min(s0, s1), s2);
>>
>> ...
>> }
>>
>> I get warning about scatter being used when writing to dstRow[0] and
>> dstRow[sizex - 1], which is logical & OK. But I also get warning about
>> undefined behavior caused
>> by all instances writing to same location, which I don't know how to
>> solve. Actually I would like to kind of force serial execution for block,
>> which
>> computes values for dstRow[0], dstRow[sizex - 1].
>>
>> Am I approaching it in wrong way ? How to solve this kind of
>> computational pattern ?
>>
>>
>> Many thanks for tips !
>>
>> Regards
>> Petr
>>
>>
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.