如何将float传递给opencl(通过PyOpenCL API)并返回python float?
我正在使用PyOpenCL。我将一个浮点数组传递给OpenCL内核。当返回float时,python不能使用C类型,并且有奇怪的值:8.27548023e-36 8.27548310e-36等。
选择 | 换行 | 行号
- float myFunc(float number, float iter_val)
- {
- float output;
- // Beginning of FOR loop #1
- for(0;iter_val-1>0;){
- if(output == 0){
- output = number*number;
- iter_val = iter_val - 1;
- }
- else{
- output = output*number;
- iter_val = iter_val - 1;
- }
- } // End of FOR loop #1
- return output;
- } //End of myFunc definition
- // Main Kernel //
- __kernel void part1(__global float* a, __global float* b, __global float* c)
- {
- unsigned int i = get_global_id(0);
- c[i] = myFunc(a[i], b[i]);
- }