HI I’m learning CUDA C at the moment in the hope that I will be able to run micro simulations of health populations in parallel rather than it taking 4days to run in Excel.
I’ve started by trying to write a kernel that takes the values of a 2D array and repeats X Ytimes in a 1D array. This is a basic step needed to initialise a population in a microsimulation.
But I get an “expected expression” error underlining the third < in the kernel call and I don’t know why. I’m using visual studio 2015 as an editor with the NVIDIA pack downloaded. I’ve stared at this for a couple of days now and could do with some help.
Thanks
Code as follows
#include “cuda_runtime.h”
#include “device_launch_parameters.h”
#include <stdio.h>
#include <stdlib.h>
#define SQUARE 2
global void makepop(int *a, int *b)
{
int tid = blockIdx.x;
int e = 0;
int i = 0;
int c = 0;
int d = 0;
if (tid < SQUARE)
{
c = a[tid, 0];
d = a[tid, 1];
for (i = e; i < d + e; i++)
b[i] = c;
e = e + d;
}
}
int main(void)
{
int a[2][2];
int b[20] = { 0 };
int *dev_b;
int *dev_a;
int c;
int d;
a[0][0] = 11;
a[0][1] = 2;
a[1][0] = 22;
a[1][1] = 10;
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<int>();
cudaArray *cuArray;
cudaMallocArray(&cuArray, &channelDesc, 2, 2);
cudaMalloc((void**)&dev_b, sizeof(int));
cudaMemcpy2D(&cuArray, SQUARE, a, sizeof(float)*SQUARE, sizeof(int)*SQUARE, SQUARE, cudaMemcpyHostToDevice);
cudaMemcpy(&dev_b, b, sizeof(int), cudaMemcpyHostToDevice);
makepop<<<1,1>>>(dev_a, dev_b);
cudaMemcpy(b, &dev_b, sizeof(int), cudaMemcpyDeviceToHost);
for (c = 0; c < 20; c++)
{
printf("%d\n", b[c]);
}
cudaFree(dev_a);
cudaFree(dev_b);
return 0;
}