是否有dpc+/sycl等效于cuda的atomiccas?

发布于 2025-02-02 05:39:09 字数 446 浏览 3 评论 0原文

从我的理解来看,CUDA的atomiccas具有以下定义(这是四个)

int atomicCAS(int* address, int compare, int val);

,它在原子上比较了位于address> address> 的值(在doc 中命名)在“全局共享”内存中使用比较,如果平等将值分配给val,否则什么都不做。在这两种情况下,返回

查看SYCL API,我只能找到compare_exchange_strong,不幸的是,它并没有使用与上述相同的命名,它将old比较,如果不成功,则会改变比较(通过引用传递)。

From my understanding, CUDA's atomicCAS has the following definition (this is one of the four)

int atomicCAS(int* address, int compare, int val);

and it compares atomically the values located at address (named in the doc old) in the global shared memory with compare and in case of equality assigns the value to val, otherwise does nothing. In both cases returns old.

Looking at SYCL API, I can only find compare_exchange_strong which, unfortunately, does not do what I'm looking for as, using the same naming as above, it compares old with compare and if not successful, alters compare (which is passed by reference).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2025-02-09 05:39:09

正如彼得·科德斯(Peter Cordes)在评论中指出的那样,sycl :: compare_exchange_strong是正确的选择。从SYCL 2020 Rev。 4 的描述compare_exchange_strong

原子上比较了此atomic_ref预期的值进行比较。如果值相等,则将引用对象的值替换为所需的的值;否则将引用对象的原始值分配给预期

So,

int old = compare;
ref.compare_exchange_strong(old, val);

is, in terms of updating ref, equivalent to

old = atomicCAS(address, compare, val);

If you are interested, you can

As Peter Cordes noted in a comment, sycl::compare_exchange_strong is the right choice. From the SYCL 2020 rev. 4 description of compare_exchange_strong:

Atomically compares the value of the object referenced by this atomic_ref against the value of expected. If the values are equal, replaces the value of the referenced object with the value of desired; otherwise assigns the original value of the referenced object to expected.

So,

int old = compare;
ref.compare_exchange_strong(old, val);

is, in terms of updating ref, equivalent to

old = atomicCAS(address, compare, val);

If you are interested, you can see for yourself how hipSYCL implements sycl::compare_exchange_strong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文