Accessing tile static memory inside a lambda function RRS feed

  • Question

  • I found this really weird behavior of the AMP library. If you want to access values of an array inside a AMP lambda function you first have to either wrap it or create a view for it. If you simply access the array the compiler throws the error:

    x.cpp(11) : error C3478: 'x' : an array cannot be captured by-value

    Here's how the code might look like in that case:

    int x[3]; 
        e, // e is of type extent<1> 
        [x](index<2> idx) restrict(amp) 

        // ... 

    That's all perfectly fine. But the thing is, I want to use tile static memory / groupshared memory. But I also want to use lambda's inside my AMP lambda. But that cause's the exact same error to happen. Here's how this code might look like:

    parallel_for_each(e, [=] (index<1> idx) restrict(amp)
       tile_static uint values[256];

       auto someLambda = [=] ()  
           return values[0];


    I don't think that should happen. What can I do about it?

    Friday, June 22, 2012 10:58 PM


  • Hi Christopher,

    Your code is violating one of the restrict(amp) restrictions. You are trying to use tile_static memory in a non-tiled parallel_for_each. This is not allowed

    Assuming you fix that violation, then your code would be correct. That is because tile_static behaves the same as static unless otherwise mentioned in the open spec. In your case, it can be directly used in the inner lambda and there is no need for capturing. However, it would still not work for you. That is because of a bug in our compiler that incorrectly reports an error on “an array cannot be captured by-value” when you use [=] - sorry.

    There are a few workarounds for the compiler bug, for example you can use “[&]”.  This does not mean to capture “values” by reference. As mentioned, there is no capturing needed for tile_static variables/arrays.  FYI, if you try to explicitly capture “values” either like this [=values], or like this [&values], you will get errors.

    Thank you for reporting this bug, and I hope the work around will unblock your scenario.


    Friday, June 22, 2012 11:22 PM