gpt4 book ai didi

c++ - 我可以显式调用 restrict(amp) callable 以确保它在加速器上运行吗

转载 作者:行者123 更新时间:2023-11-30 05:43:34 25 4
gpt4 key购买 nike

我有:

void foo() restrict(amp)
{
}

现在如果我这样做:

void main()
{
foo();
}

它会在加速器上运行吗?如果不是,如何在不使用 parallel_for_each 循环的情况下在加速器中运行 foo()

最佳答案

这不是真正的合法代码。 foo() 被标记为 restrict(amp) 这意味着它只能在 C++AMP 内核中运行。标记为 restrict(amp) 的函数只能从加速运行的代码中调用,换句话说,从 parallel_for_each lambda 中调用,该 lambda 也是 restrict(amp)

void foo() restrict(amp)
{
}

void main()
{
parallel_for_each(e, [=](index<2> idx) restrict(amp)
{
foo()
});
}

如果您将 foo() 标记为 restrict(amp,cpu) 那么您也可以从 CPU 调用它,前提是 foo() 中的代码 满足 AMP 和 CPU 代码的要求。

关于c++ - 我可以显式调用 restrict(amp) callable 以确保它在加速器上运行吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30154794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com