I have tried everything to allocate a struct containing a double pointer to device memory using cudaMalloc. I know this question has been asked multiple times yet the question is always for only a single pointer in a structure. I cannot flatten the data because training.data[] index is linked to many other functions of the program. If i cant index the data using training.data[1][n], training.data[2][n]……etc then i cant make use of the data. Ive tried this but keep getting a memory access violation error:
typedef struct training_data {
float** data;
float* answer;
float error_rate[500];
}create_training_structure;
create_training_structure *GPUtraining;
float** tempDataSamples;
float* tempData;
cudaStatus = cudaMalloc((void**)&GPUtraining, sizeof(create_training_structure));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMalloc for GPUtraining Structure failed: %sn", cudaGetErrorString(cudaStatus));
}
for (int rows = 0; rows < trainingRows; ++rows) {
// Allocate memory for data (2D array) on GPU. training[X][]
cudaStatus = cudaMalloc((void**)&tempDataSamples, trainingRows * sizeof(float*));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMalloc for GPUtraining[X][] failed: %sn", cudaGetErrorString(cudaStatus));
}
}
// Allocate memory for data (2D array) on GPU. training[X][]
for (int i = 0; i < trainingRows; ++i) {
cudaStatus = cudaMalloc((void**)&tempData, (trainingColumns + BIAS_NEURON) * sizeof(float));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMalloc for GPUtraining[][X] failed: %sn", cudaGetErrorString(cudaStatus));
}
}
for (int rows = 0; rows < trainingRows; ++rows) {
for (int columns = 0; columns < trainingColumns; columns++) {
cudaMemcpy(&(GPUtraining->data[rows][columns]), &(training.data[rows][columns]), sizeof(float*), cudaMemcpyHostToDevice);
}
}