Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wrote the following kernel code, but it gave me the following warning. I have tried different solutions but failed. plz any suggestion would help

28:48: warning: incompatible integer to pointer conversion passing '__global int' to parameter of type '__private int *' [-Wint-conversion]
            array_dist[i] = Euclidean_distance(X_train[i],data_point[j]);
                                               ^~~~~~~~~~


my code:
inline float Euclidean_distance(int * array_point_A, int * array_point_B) {
    float sum = 0.0;

    float  w[20] = { 0.0847282, 0.0408621, 0.105036, 0.0619821, 0.0595455, 0.0416739, 0.0181147, 0.00592921,
     0.040049, 0.0766054, 0.0441091, 0.0376111, 0.0124285, 0.0733558, 0.0587338, 0.0303001, 0.0579207, 0.0449221,
          0.0530462, 0.0530462 };

    for (int i = 0; i < 20; ++i) {
        float a = array_point_A[i] - array_point_B[i];
        float wieghted_distance = w[i] * (a * a);
        sum += wieghted_distance;

    }
    return sqrt(sum);
}



__kernel void KNN_classifier(__global  int * restrict X_train, __global  int * restrict Y_train, __global  int * restrict data_point, int k)
{
     
    float array_dist[4344] = {};
    int index_arr[4344] = {};
    for (int i = 0; i < 4344; ++i) { 
        for (int j = 0; j < 20; ++j) {
            array_dist[i] = Euclidean_distance(X_train[i],  data_point[j]);
            index_arr[i] = i;
        }
    }


What I have tried:

I tried several solution but no improvement
Posted
Updated 29-Aug-21 22:28pm

X_train is a parameter, and is declared as:
__global  int * restrict X_train

__kernel void KNN_classifier(__global  int * restrict X_train, __global  int * restrict Y_train, __global  int * restrict data_point, int k)

The method you are calling expects an int *:
inline float Euclidean_distance(int * array_point_A, int * array_point_B)

array_dist[i] = Euclidean_distance(X_train[i],  data_point[j]);
When you select an element from an array with an index, you get the item, not a pointer to the item.
So if you pass in a pointer to an integer and then select an element from that, you get an integer, not a pointer to an integer (remember, the name of an array is a pointer to the first element of that array - so a pointer to a value is also an array of those values).

Either use the address of operator '&' or pass the whole array when you call the second method.
 
Share this answer
 
v4
Comments
prother123 29-Aug-21 12:42pm    
Thank you for reply. So what should I update my code with? Please write the code after modification.
OriginalGriff 29-Aug-21 13:39pm    
I can';t - I have no idea of the context, or exactly what else you are trying to do!
Look at your declaration of Euclidean_distance :
C++
inline float Euclidean_distance(int * array_point_A, int * array_point_B) {
// both parameters are pointers to arrays

And now the call:
C++
array_dist[i] = Euclidean_distance(X_train[i],  data_point[j]);
// but you are trying to pass single integers

Change the call to:
C++
array_dist[i] = Euclidean_distance(X_train,  data_point);

However, looking at the implementation of your code that is still going to cause problems, since the Euclidean_distance code iterates through 20 elements of each array, but you are calling it for each of the 20 elements of the data_point array.

I think you need to consider very carefully what you are trying to do with this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900