我在第 10 行遇到错误__global__ void kernel
。我一定做错了什么?这是我的代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <time.h>
#define F 20
__global__ void kernel(double* dev_fitness,double* dev_prob, F)
{
int i = blockIdx.x;
double maxfit;
maxfit=dev_fitness[0];
if(i<F)
{
if(dev_fitness[i]>maxfit)
maxfit=dev_fitness[i];
}
if(i<F)
{
dev_prob[i]=(0.9*(dev_fitness[i]/maxfit))+0.1;
}
}
double prob[F];
double fitness[F];
int main()
{
double* dev_fitness;
size_t fitnessSize= F*sizeof(double);
cudaMalloc(&dev_fitness,fitnessSize);
cudaMemcpy(dev_fitness,fitness,fitnessSize,cudaMemcpyHostToDevice);
//--------------
double* dev_prob;
size_t probSize=F*sizeof(double);
cudaMalloc(&dev_prob,probSize);
cudaMemcpy(dev_prob,prob,probSize,cudaMemcpyHostToDevice);
kernel <<<F,1>>> (dev_fitness,dev_prob,F);
cudaMemcpy (fitness,dev_fitness,fitnessSize,cudaMemcpyDeviceToHost);
cudaMemcpy (prob,dev_prob,probSize,cudaMemcpyDeviceToHost);
cudaFree (dev_fitness);
cudaFree (dev_prob);
}