How to convert following OpenCV c++ to Cuda

How can I convert the following c++ OpenCV code to Cuda?

void ndgridFunction(int height, int width, Mat *rs, Mat *cs){
        for(int i = -(height-1); i<= height; i++){
            for(int j= -(width - 1);j <= width; j++){
                cs->at<float>(i+(height - 1 ),j+(width - 1)) = float(j);
                rs->at<float>(i+(height - 1 ),j+(width - 1)) = float(i);
            }
        }
    }

And here is my main function, the results should be same.

int main()
{
 int height = 15;
 int width = 20;

 Mat cs     = Mat(height*2, width*2, CV_32F);
 Mat rs     = Mat(height*2, width*2, CV_32F);

 ndgridFunction(height,width, &rs, &cs);
 cout<<cs<<endl;

 return 0;
 }

Results is [-19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20; -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20…]