In the constructor I fill the array on the device side.
but now I want to execute reverse function on the array.
 using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
__global__ void generateVector(int *data,int count){
    int tid = blockIdx.x;
    data[tid] = -tid;
}
__global__ void reverseArray(int *data,int count){
    int tid = blockIdx.x;
    data[tid] = tid;
}
class FData{
private:
    int *data;
    int size;
public:
    FData(int sizeP){
        size = sizeP;
        data = new int[size];
        int *devA;
        cudaMalloc((void**) &devA, size * sizeof(int));
        generateVector<<<size,1>>>(devA,size);
        cudaMemcpy(data,devA, size * sizeof(int),cudaMemcpyDeviceToHost);
        cudaFree(devA);
    }
    ~FData(){
        delete [] data;
    }
    int getSize(){
        return size;
    }
    int elementAt(int i){
        return data[i];
    }
    void reverse(){
        int *devA;
        cudaMalloc((void**) &devA, sizeof(int));
        reverseArray<<<size,1>>>(devA,size);
        cudaMemcpy(data,devA,size * sizeof(int),cudaMemcpyDeviceToHost);
        cudaFree(devA);
    }
};
int main(void) {
    FData arr(30);
    cout << arr.elementAt(1);
    arr.reverse();
    cout << arr.elementAt(1);
    return 0;
}
It still prints the values which I filled in the constructor. What is the problem here? How can i solve it? What is going wrong?
 
     
    