How do I pass floats to opencl (via the PyOpenCL API) and return python floats?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jory R Ferrell
    New Member
    • Jul 2011
    • 62

    How do I pass floats to opencl (via the PyOpenCL API) and return python floats?

    I am using PyOpenCL. I pass a array of floats to the OpenCL kernel. When the floats are returned, python can't use the types C types and has strange values:8.275480 23e-36 8.27548310e-36, etc.


    Code:
    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]);
    
        
    }
Working...