python - 如何将多维数组传递给 pyopencl.algorithm.copy_if() -- PyOpenCL,
问题描述
以下代码给了我警告“警告:不兼容的整数到指针转换将'__global int'传递给'__global int *'类型的参数;使用&获取地址”并且不会产生所需的结果。
import pyopencl as cl
import pyopencl.array
import pyopencl.algorithm
import numpy as np
platform = cl.get_platforms()
my_devices = platform[0].get_devices(device_type=cl.device_type.ALL)
ctx = cl.Context(devices=my_devices)
queue = cl.CommandQueue(ctx)
aryary = np.array([[10, 11, 12, 13, 14, 15, 16, 17], [1, 2, 3, 4, 0, 0, 0, 0], [108, 0, 0, 0, 0, 0, 0, 0]], np.int32)
cl_aryary = cl.array.to_device(queue, aryary)
lenary = np.array([8, 4, 1], np.int32)
cl_lenary = cl.array.to_device(queue, lenary)
result = cl.algorithm.copy_if(
cl_aryary,
"sum_array(ary[i], len[i]) == 108",
extra_args=[('len', cl_lenary)],
preamble='''
int sum_array(__global int *a, int num_elements)
{
int i, sum=0;
for (i=0; i<num_elements; i++)
{
sum = sum + a[i];
}
return(sum);
}
''',
queue=queue
)
print(result)
编辑:供参考:
https://documen.tician.de/pyopencl/algorithm.html#module-pyopencl.algorithm
解决方案
函数的调用int sum_array(__global int *a, int num_elements)
在该行中,"sum_array(ary[i], len[i]) == 108",
但应该有一个指针,而不是函数中定义的数组元素。那将是:
"sum_array(&ary[i], len[i]) == 108",
推荐阅读
- c++ - C++ - 刷新 std::cout 后不得到结果
- excel - Excel - 带符号的条件格式
- android - Android下载apk文件并保存到INTERNAL STORAGE
- c# - 在 Umbraco CMS 项目中动态添加文本到视图
- c# - 为什么我的 Windows 服务没有因致命错误而停止?
- javascript - jQuery - 翻转 DIV 问题
- javascript - 无法理解 Promise 并捕捉行为
- c++ - VS 2017 项目中的恒定 LNK1104 错误
- r - r 传单:如何获得标记被拖到的纬度/经度?
- ibm-appid - 我们如何使用 IBM Appid 对 Kibana 用户进行身份验证?