質問

I have a CUDA C code, when I try to compile it, nvcc gives me an error with an undefined identifier error: identifier "cudamalloc" is undefined, identifier "cudamemcpy" is undefined.

I'm running Windows 7 with Visual Studio 10 and CUDA Toolkit 4.0

I have installed Cuda on drive "C" and Visual Studio on drive "E" but im not sure that it is the problem.

I use this command to compile:

nvcc -o ej1b ej1b.cu

and this is my program:

#include <cuda.h>
#include <cstdio>
#include <cuda_runtime_api.h>
#include <device_functions.h>
#include "device_launch_parameters.h"
#include <stdio.h>
#include <stdlib.h>

const int N = 512;
const int C = 5;


void init_CPU_array(int vec[],const int N){
  unsigned int i;
  for(i = 0; i < N; i++) {
    vec[i] = i;
  }
}

__global__ void kernel(int vec[],const int N, const int C){
  int id = blockIdx.x * blockDim.x + threadIdx.x;
  if(id<N)
    vec[id] = vec[id] * C;
}

int main(){
int vec[N];
int vecRES[N];
int *vecGPU;
unsigned int cantaloc=N*sizeof(int);
init_CPU_array(vec,N);
cudamalloc((void**)&vecGPU,cantaloc);
cudamemcpy(vecGPU,vec,cantaloc,cudaMemcpyHostToDevice);
dim3 dimBlock(64);
dim3 dimGrid((N + dimBlock.x - 1) / dimBlock.x);
printf("-> Variable dimBlock.x = %d\n",dimBlock.x); 
kernel<<<dimGrid, dimBlock>>>(vecGPU, N, C);
cudaThreadSynchronize();
cudamemcpy(vecRES,vecGPU,cantaloc,cudaMemcpyDeviceToHost);
cudaFree(vecGPU);
printf("%s \n","-> Resultados");
int i;
for(i=0;i<10;i++){
    printf("%d      ",vecRES[i]);
    printf("%d \n",vec[i]);
}
return 0;

I used all those #include because I don't know where the problem is.

役に立ちましたか?

解決

If you read the documentation, you will find the API calls are cudaMalloc and cudaMemcpy. C and C++ are case sensitive languages and you have the names incorrect.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top