c++ - 有什么方法可以在 OpenCL 中使用屏障来实现原子功能?
问题描述
我有一些使用 atomic_inc 的代码,但不幸的是 Xilinx FPGA 中的 OpenCL 支持缺乏原子功能。
Xilinx 提供对屏障的支持(clk_global_mem_fence 和 clk_local_mem_fence)
如果缺少原子函数,您知道有什么方法可以在下面的代码中替换“atomic_inc”吗?我可以创建一些可以在 OpenCL 中使用障碍的函数吗?
非常感谢
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search(__global hash_t* restrict hashes, __global uint* restrict output, const ulong target)
{
uint gid = get_global_id(0);
uint offset = get_global_offset(0);
__global hash_t *hash = &(hashes[gid-offset]);
bool result = (hash->h8[3] <= target);
if (result) {
// TODO(ajaraber): Disable atomic_inc as not available in Xilinx FPGAs
#ifdef ATOMIC_SUPPORTED
uint i = atomic_inc(output + 0xFF);
#else
uint i = atomicAdd(output+0xFF, 1);
#endif
if (i < 0xFF)
output[i] = SWAP4(gid);
}
// TODO(ajaraber): Use memory barrier but only for Xilinx FPGAs
#ifndef ATOMIC_SUPPORTED
if (WORKSIZE != 1) {
barrier(CLK_GLOBAL_MEM_FENCE);
}
#endif
}
解决方案
推荐阅读
- spring - Spring 5.0.5 @Value 无法解析为正确的类型
- python - 使用 Boosting 树在 sklearn 中生成特征
- symfony4 - Symfony 4 使用 URL 检查数据库是否存在页面,否则 404
- postgresql - 将一列字符串与其他表中的列匹配
- objective-c - 从另一个项目复制类并删除 XCode 中的连接
- javascript - window[name] 相当于动态访问 const 和 let 声明
- android - 仅在我的生产环境中来自 Google API 的“401:无效凭据”
- javascript - Cloud Functions for Firebase onWrite 触发器:snapshot.val 不是函数
- header - 使用 AWS Amplify 登录时将 JWT 添加到所有 GraphQL/AppSynce 请求
- r - R:重新编码变量的有效方法是什么?我如何按比例分配?