best way to convert a c++ program to use on the kernal

Hi all new here, I’m about five weeks into my Cuda trip, I have the c++ program that makes a data set of moves to use for parallel programming I need to convert it to work on the GPU.

I’m new to Cuda, I have this c++ program I need to convert to run on the GPU. I’m not sure on how to convert it, if you could help me this would be great.

from my understanding anything that access the hard drive cannot be sent to the GPU, so getdata and GenerateData functions can be left alone, the display results would be called after coping the device memory back to the host.

that leaves me with three function to convert, and this is where I am stuck…

I have looked over many documents over the week and its not sinking in, can anyone point me in the right direction?

#include <stdio.h>
#include
#include
#include <time.h>

using namespace std;

const int DATA_SET_SIZE = 100000;
const int MOVES = 3;
const int PERMUTATIONS = MOVES * MOVES;
int NAB[PERMUTATIONS];
int data1[DATA_SET_SIZE];

// Generate a random set of integers each being in the range 0 to MOVES - 1
// Save numbers to file to ensure tests can be repeated.
void GenerateData(){
ofstream out(“data.dat”, ios::out | ios::binary);
for(int n = 0; n < DATA_SET_SIZE; n++){
int i = rand() % MOVES;
out.write((char *) &i, sizeof(i));
}
out.close();
}

void InitialiseNAB(){
for(int n = 0; n <PERMUTATIONS;n++){
NAB[n] = 0;
}
}

// Populate data array with contents of file
void GetData(){
ifstream in(“data.dat”, ios::in | ios::binary);
for(int n = 0; n < DATA_SET_SIZE; n++){
in.read((char *) &data1[n], sizeof(int));
}
in.close();
}

int GetIndex(int firstMove, int secondMove){
if (firstMove == 0 && secondMove == 0) return 0;
if (firstMove == 0 && secondMove == 1) return 1;
if (firstMove == 0 && secondMove == 2) return 2;
if (firstMove == 1 && secondMove == 0) return 3;
if (firstMove == 1 && secondMove == 1) return 4;
if (firstMove == 1 && secondMove == 2) return 5;
if (firstMove == 2 && secondMove == 0) return 6;
if (firstMove == 2 && secondMove == 1) return 7;
if (firstMove == 2 && secondMove == 2) return 8;
}

void DisplayNAB(){
int check = 0;
cout << endl;
for (int n = 0; n < PERMUTATIONS; n++){
cout << "Index " << n << " : " << NAB[n] << endl;
check += NAB[n];
}
// Total should be one less than DATA_SET_SIZE as first value doesn’t have a previous value to compare.
cout << "Total : " << check << endl;
}

//
void PopulateNAB(){
int index;
int previous = data1[0];
for(int n = 1; n < DATA_SET_SIZE;n ++){
index = GetIndex(previous, data1[n]);
NAB[index]++;
previous = data1[n];
}
}

int main(){
srand(time(NULL));
GenerateData();
GetData();
PopulateNAB();
DisplayNAB();
return 0;
}

This may be of interest:

[url]https://devblogs.nvidia.com/even-easier-introduction-cuda/[/url]

Thanks ill have a read!