Suppose I have a class "A", which has a method "void AMP_call()" that calls paralel_for_each in which another method, "float amp_function(float) restrict(amp)". When I call that method, can it then use members of "A"?
class A
{
void AMP_call();
float amp_function(float) restrict(amp); // do something on a device
float allowed_variable;
std::vector<bool> not_allowed;
};
void A::AMP_call()
{
// ... prepare some array views ...
parallel_for_each(
result.extent,
[=](index<1> idx) restrict(amp)
{
// do some stuff...
result[idx] = amp_function(input); // can I do this?
}
}
float A::amp_function(float) restrict(amp)
{
// do some stuff, access member variables (also, what happens if this function tries to access "not_allowed"?)
// can I access "allowed variable"?, if not, how?
return something;
}
EDIT: Another way to frame my question, perhaps to make it easier to understand what I am after, would be that I want to know what happens if an amp-restricted method is called where the body of the class itself (which is not amp-compatible and afaik doesn't have to be since it's not passed to the device) may contain members that are not amp-compatible.
All of the msdn blogs I could find deal with which functions and methods can be called from within a parallel_for_each loop, but not with which variables are available to the lambda function itself.
what happens if this function tries to access "not_allowed"?
Why you won't just try that instead of asking trivial question it will take 1 minute to test yourself and answer to which you can find all over the net?
In answer to the content of your reply, I am trying to understand how AMP applies to amp restricted methods, which may or may not be member functions of non-amp compatible classes (as far as I know this is allowed). If you know of a link that can educate me about the use of amp-restricted functions in non-amp compatible classes (I have read the msdn amp restrictions blogs and they do not address this particular issue) please provide it.
In future you would do well not assume the worst of people. I come here for a hand when I am unable to find answers myself. I always do my research and try to provide code samples that illustrate the issue as clearly as possible, and I don't appreciate being derided for it. Please consider removing or editing your reply in case others come here with similar queries.
a) restrict keyword is not part of C++ and so you should check your compiler documentation to know what it does in your case.
I assume it is Microsoft specific AMP version. (BTW you will probably have more luck in windows programming section)
Link from MSDN documentation on restrict: http://blogs.msdn.com/b/nativeconcurrency/archive/2011/12/19/restrict-amp-restrictions-part-0-of-n-introduction.aspx
Answer to your question is probably no, because vector<bool> uses compound objects, pointer casting and other unsupported things.
If you tried to do that compiler probably would give you a descriptive error pointing to exact cause why error is happened and you would have more information on it and I honestly does not see how that error or lack of it would not answer your question.
That blog link doesn't mention access to members for restrict(amp) classified methods, so unless I've missed something the first time around those links don't really address my question.
Answer to your question is probably no, because vector<bool> uses compound objects, pointer casting and other unsupported things.
I'm not sure which question you mean, but if it's line 28 then I don't see why it would be a problem (allowed_variable is a type float). But then it's not specifically transferred to parallel_for_each, so I don't know whether or how to access it, hence my problem.
If you tried to do that compiler probably would give you a descriptive error pointing to exact cause why error is happened and you would have more information on it and I honestly does not see how that error or lack of it would not answer your question.
Unfortunately I don't have a AMP compiler at the moment. And yes, I'm trying to understand the Microsoft AMP implementation. In any case, I don't like to just dive in without first understanding the theory behind what I am doing.
EDIT: I've reposted the original question in windows programming as per your suggestion.
but if it's line 28 then I don't see why it would be a problem
I mean following line: //also, what happens if this function tries to access "not_allowed"?
Next line was added after I started to write post.
I believe that access to allowed_variable would work if it is properly aligned.However there is little to no documentation on AMP and best, if not only, source of information is implementation: Microsoft compiler and its behavior.
I think I might have found my answer; while lambdas have access to their enclosing scope, the lambda passed to parallel_for_each() has access only to the scope of that function, not to the calling function (which may or may not be a method). Therefore, that lambda should never have access to the parent class and should never be able to access members in the first place. Now I really just need to find out how to pass information to parallel_for_each but I should be able to do that for myself.